CS 330 Lecture 14 – Assembly
Agenda
- what ?s
- Human Resource Machine
- hello, x86
- adding two globals
- printing
- getting user input
- counting
TODO
- Read Programming from the Ground Up, from chapter 1 through section Planning the Program of chapter 3. Click on Download Area to find the PDF. Write down 2-3 questions or observations on a 1/4 sheet.
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