teaching machines

CS 330 Lecture 7 – Assembly

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

Agenda

TODO

Think About This

  1. Will we need 128-bit machines soon?
  2. What happens when a function assigns a value to one of its parameters?
  3. When is global data allocated?

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.

Von Neumann

John Backus: “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.”

Code

image_gallery.html

<!DOCTYPE html>
<html>
<head>
  <title>...</title>
</head>
<body>
  <img src="dog.png" />
  <img src="cat.png" />
  <img src="horse.png" />
  <img src="blugold.png" />
</body>
</html>

imagefixerupper.rb

#!/usr/bin/env ruby

text = IO.read('image_gallery.html')

puts text.gsub(/(?<=src=")(?=[^"]+\.png")/, 'img/')

exit.s

.section .data

.section .text
.globl main

main:
  pushl $2
  call exit

some_data.s

.section .data
i:
  .long 13
j:
  .long 14
k:
  .long 14
out_format:
  .ascii "My favorite number is %d.\n\0"

.section .text
.globl main

main:
  pushl i
  pushl $out_format
  call printf
  addl $8, %esp

  pushl $2
  call exit

Haiku

I have a question
I raise my hand to ask it
And trace my palm lines