CS 330 Lecture 6 – Hardware Pushing
Agenda
- imperative programming
- assigning and mutating variables
- conditionals and loops
- von Neumann
- a few hardware functions
- assembly code
- disk to RAM to registers
- returning a result to the shell
- compiling
- debugging with gdb
- adding two numbers
- printf
- quadrupling
- cmp and jmp
- a coin tosser
- a for loop
TODO
- Read pages 22-33 of Programming from the Ground Up, sections Finding a Maximum Value through the end of Chapter 3.
Von Neumann Languages
John Backus said:
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.
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, but reference the register that holds it in your calculations, not the literal value.
Code
setreturn.s
.section .text
.globl main
main:
# Pass one parameter to exit.
pushl $27
call exit
add.s
.section .text
.globl main
main:
movl $5, %eax
movl $6, %ebx
addl %ebx, %eax # %eax += %ebx
# subl %ebx, %eax # %eax -= %ebx
pushl %eax
call exit
favorite.s
.section .data
format_string:
.asciz "My favorite number is %d!"
number:
.long 786
.section .text
.globl main
main:
pushl number
pushl $format_string
call printf
addl $8, %esp
pushl $0
call exit
Haiku
“You, number. Go there.
And you, join up with that one.”
Whence comes the magic?
And you, join up with that one.”
Whence comes the magic?