CS 330 Lecture 7 – Flow control
February 6, 2013 by Chris Johnson. Filed under
Deprecated: Creation of dynamic property WP_Term::$cat_ID is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 378
Deprecated: Creation of dynamic property WP_Term::$category_count is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 379
Deprecated: Creation of dynamic property WP_Term::$category_description is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 380
Deprecated: Creation of dynamic property WP_Term::$cat_name is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 381
Deprecated: Creation of dynamic property WP_Term::$category_nicename is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 382
Deprecated: Creation of dynamic property WP_Term::$category_parent is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 383
Deprecated: Creation of dynamic property WP_Term::$cat_ID is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 378
Deprecated: Creation of dynamic property WP_Term::$category_count is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 379
Deprecated: Creation of dynamic property WP_Term::$category_description is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 380
Deprecated: Creation of dynamic property WP_Term::$cat_name is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 381
Deprecated: Creation of dynamic property WP_Term::$category_nicename is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 382
Deprecated: Creation of dynamic property WP_Term::$category_parent is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 383
Deprecated: Creation of dynamic property WP_Term::$cat_ID is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 378
Deprecated: Creation of dynamic property WP_Term::$category_count is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 379
Deprecated: Creation of dynamic property WP_Term::$category_description is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 380
Deprecated: Creation of dynamic property WP_Term::$cat_name is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 381
Deprecated: Creation of dynamic property WP_Term::$category_nicename is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 382
Deprecated: Creation of dynamic property WP_Term::$category_parent is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 383
cs330, lectures, spring 2013.
Agenda
- popping the ?stack
- stack restoration
- program this
- debugging with gdb
- quadrupling
- cmp and jmp
- a coin tosser
- a for loop
TODO
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
quadruple.s
.section .data
format_string:
.asciz "%d quadrupled is %d\n"
.section .text
.globl main
main:
movl $4, %eax
movl %eax, %ebx
addl %eax, %eax
addl %eax, %eax
pushl %eax
pushl %ebx
pushl $format_string
call printf
addl $12, %esp
pushl $0
call exit
heads_tails.s
.section .data
format_string:
.asciz "The random number was: %d\n"
heads_message:
.asciz "Heads"
tails_message:
.asciz "Tails"
.section .text
.globl main
main:
pushl $58
call srand
call rand
andl $1, %eax
cmpl $1, %eax
je tails
heads:
pushl $heads_message
call printf
jmp quit
tails:
pushl $tails_message
call printf
quit:
# pushl %eax
# pushl $format_string
# call printf
# addl $8, %esp
pushl $0
call exit
Haiku
Unimperative Marriage
Programming humans
Share int’rests, not positions
Those are for machines