CS 330 Lecture 7 – Assembly
Agenda
- what ?s
- zero-width assertions
- think about this
- Von Neumann
- memory footprint of a process
- how to do things from a high-level language in assembly
- exit
- declare globals
- print some numbers
- sum some numbers
- getting input from user
- heads/tails generator
TODO
- Read Programming From The Ground Up, from the beginning through page 19.
- What’s a pointer?
- 1/4 sheet.
Think About This
- Will we need 128-bit machines soon?
- What happens when a function assigns a value to one of its parameters?
- When is global data allocated?
Program This
Write a little assembly program that moves a value into a register, quadruples it, and then prints out a message of the form: “4 quadrupled is 16.” Use a number of your choosing.
Von Neumann
John Backus: “Von Neumann programming languages use variables to imitate the computer’s storage cells; control statements elaborate its jump and test instructions; and assignment statements imitate its fetching, storing, and arithmetic.”
Code
image_gallery.html
<!DOCTYPE html>
<html>
<head>
<title>...</title>
</head>
<body>
<img src="dog.png" />
<img src="cat.png" />
<img src="horse.png" />
<img src="blugold.png" />
</body>
</html>
imagefixerupper.rb
#!/usr/bin/env ruby
text = IO.read('image_gallery.html')
puts text.gsub(/(?<=src=")(?=[^"]+\.png")/, 'img/')
exit.s
.section .data
.section .text
.globl main
main:
pushl $2
call exit
some_data.s
.section .data
i:
.long 13
j:
.long 14
k:
.long 14
out_format:
.ascii "My favorite number is %d.\n\0"
.section .text
.globl main
main:
pushl i
pushl $out_format
call printf
addl $8, %esp
pushl $2
call exit
Haiku
I have a question
I raise my hand to ask it
And trace my palm lines
I raise my hand to ask it
And trace my palm lines