teaching machines

CS 330 Lecture 9 – Assembly

February 10, 2014 by . Filed under cs330, lectures, spring 2014.

Agenda

TODO

Think About This

Code

get_two.s

.section .data
# a: 
  # .long 7 
# b: 
  # .long 8 
in_format:
  .asciz "%d %d"

.section .bss
.lcomm a, 4
.lcomm b, 4

.section .text
.globl main

main:
  pushl $a 
  pushl $b
  pushl $in_format
  call scanf 
  addl $12, %esp

  movl a, %eax
  addl b, %eax

  pushl %eax
  call exit

headxortails.s

.section .data
out_format:
  .asciz "Your RANDOM number is %d\n"
heads_message:
  .asciz "HEAD!"
tails_message:
  .asciz "TAIL!"

.section .text
.globl main

main:
  pushl $0
  call time
  addl $4, %esp
  
  # current nseconds since epoch is in %eax

  pushl %eax
  call srand
  addl $4, %esp

  call rand

  # %eax holds our random number
  andl $1, %eax
  # andl %eax, $1 

  # %eax is either 0 or 1

  cmpl $0, %eax
  je tails

heads:
  pushl $heads_message
  call printf
  addl $4, %esp
  jmp quit

tails:
  pushl $tails_message
  call printf
  addl $4, %esp

quit:
  pushl %eax
  pushl $out_format
  call printf
  addl $8, %esp

  pushl %eax
  call exit

Haiku

They didn’t see them
Failures, one through ninety-nine
They called it talent