teaching machines

CS 330 Lecture 6 – Hardware Pushing

February 3, 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

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?