teaching machines

CS 330 Lecture 14 – Assembly

February 24, 2016 by . Filed under cs330, lectures, spring 2016.

Agenda

TODO

Note

Now that we’ve implemented our own little language, we begin our descent into existing languages. We start at the very simplest language of all: assembly. I’ll be perfectly honest, I don’t write assembly and you may not either. So why do we discuss it? Because assembly still exists under all the layers of our high-level languages, and many of the features of our high-level languages are direct responses to things that happen at this low level.

Over the next few lectures, we will examine how assembly manages data types, variable declarations, scope, flow controls, and functions.

Code

status_add.s

.section .data
a:
  .long 23
b:
  .long 4

.section .text
.globl main

main:
  movl a, %eax
  addl b, %eax

  pushl %eax
  call exit

add.s

.section .data
a:
  .long 23
b:
  .long 4
out_message:
  .asciz "%d + %d = %d\n"

.section .text
.globl main

main:
  movl a, %eax
  addl b, %eax

  # push params
  pushl %eax
  pushl b
  pushl a
  pushl $out_message
  call printf
  addl $16, %esp

  pushl $0
  call exit