teaching machines

CS 330 Lecture 7 – Flow control

February 6, 2013 by . Filed under cs330, lectures, spring 2013.

Agenda

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