computer organization lecture 4
Post on 07-Jan-2016
53 Views
Preview:
DESCRIPTION
TRANSCRIPT
Fall 2006
Lillevik 333f06-l4 1University of Portland School of Engineering
EE 333
Computer OrganizationLecture 4
Assembly language programmingALU and memory instructions
Fall 2006
Lillevik 333f06-l4 2University of Portland School of Engineering
EE 333
MIPS: Programmers View
Memory
Registers
ALU
We will design a subset of this
computer
Fall 2006
Lillevik 333f06-l4 3University of Portland School of Engineering
EE 333
Memory Usage
Program
Data
Stack Memory divided into three separate regions or segments
Fall 2006
Lillevik 333f06-l4 4University of Portland School of Engineering
EE 333
Assembly programming
Sources files are assembled, then linked
This could be compiled
Fall 2006
Lillevik 333f06-l4 5University of Portland School of Engineering
EE 333
Assembler
• Purpose: translates a program statement (source file) into an address and data (object file)
• Steps (2-pass)– Create a symbol table– Use symbol table to generate instruction as a
binary number
• Execution: OS writes program into memory, transfers control, program runs, control returns to OS
Fall 2006
Lillevik 333f06-l4 6University of Portland School of Engineering
EE 333
Program statement syntax
• Generally, free-format• Comments: begin with sharp (#)
# this is a comment
• Labels: start the beginning of a line, end with colon (:)
start:loop:end:
Fall 2006
Lillevik 333f06-l4 7University of Portland School of Engineering
EE 333
Memory addresses
• Notation: c(rx)rx = register/base
c = constant/offset
• Examples100($t0) # EA = $t0 + 100
0x2f ($22) # EA = $22 + 0x 2f
($sp) # EA = $sp, c = 0
Fall 2006
Lillevik 333f06-l4 8University of Portland School of Engineering
EE 333
Directives
• Provides assembler information• Start with dot (.)• Examples
.text # start text segment
.data # start data segment
.asciiz # null terminated string
.word # insert word data
Fall 2006
Lillevik 333f06-l4 9University of Portland School of Engineering
EE 333
A typical line of code
label: opCode $destination, $operand1, $operand2, #comment
Examplesloop: li $t0, 2 # initialize $t0 = 2
calc: add $t1, $t3, $t1 # $t1 = $t3 + $t1
nop # do nothing
mult $s2, $s3 # hi:lo = $s2 x $s3
Fall 2006
Lillevik 333f06-l4 10University of Portland School of Engineering
EE 333
Program Structure
Labels
Program Directives
Fall 2006
Lillevik 333f06-l4 11University of Portland School of Engineering
EE 333
Simple Program
Fall 2006
Lillevik 333f06-l4 12University of Portland School of Engineering
EE 333
Let’s run the program
Fall 2006
Lillevik 333f06-l4 13University of Portland School of Engineering
EE 333
Write the program?Subtract 3 from 5 and leave in $t2
Fall 2006
Lillevik 333f06-l4 14University of Portland School of Engineering
EE 333
Instruction Classes
• Arithmetic and logic
• Load
• Store
• Comparison
• Branch and jump
• Data Movement
• Floating Point
Fall 2006
Lillevik 333f06-l4 15University of Portland School of Engineering
EE 333
Arithmetic and Logic
Instruction Example Meaningadd add $s1, $s2, $s3 $s1 = $s2 + $s3
sub sub $s1, $s2, $s3 $s1 = $s2 - $s3
add immediate addi $s1, $s2, 100 $s1 = $s2 + 100
multiply mult $s2, $s3 hi:lo = $s2 x $s3
divide div $s2, $s3 lo = $s2 / $s3
hi = $s2 mod $s3
Only registers used for operands
Fall 2006
Lillevik 333f06-l4 16University of Portland School of Engineering
EE 333
Loads (reg mem)
Instruction Example MeaningLoad word
(32 bits)
lw $s1, 100 ($s2) $s1 = mem[$s2 + 100]
Load byte unsigned
(8 bits)
lbu $s1, 100($s2) $s1 = mem[$s2 + 100]
Load address la $a0, data $a0 = address of data:
Load immediate li $t4, 18 $t4 = 0x 12
The point of reference is a register
Fall 2006
Lillevik 333f06-l4 17University of Portland School of Engineering
EE 333
Stores (reg mem)
Instruction Example MeaningStore word
(32 bits)
sw $s1, 100 ($s2) mem[$s2 + 100] = $s1
Store byte
(8 bits)
sb $s1, 100 ($s2) mem[$s2 + 100] = $s1
The point of reference is a register
Fall 2006
Lillevik 333f06-l4 18University of Portland School of Engineering
EE 333
Accessing Memory
• Use the la instruction to place address in a register
• Use the load/from & store/to address saved in the register
la $t0, var # $t0 = address of var:
lw $v1, ($t0) # $v1 = varsw $s0, 4($t0) # mem[var + 4] = $s0
Fall 2006
Lillevik 333f06-l4 19University of Portland School of Engineering
EE 333
Write the program?betaalpharesult 6
NOTE: data movement,mflo $reg
Fall 2006
Lillevik 333f06-l4 20University of Portland School of Engineering
EE 333
Fall 2006
Lillevik 333f06-l4 21University of Portland School of Engineering
EE 333
Write the program?Subtract 3 from 5 and leave in $t2
Fall 2006
Lillevik 333f06-l4 22University of Portland School of Engineering
EE 333
Write the program?betaalpharesult 6
top related