Download presentation
Presentation is loading. Please wait.
Published byIvy Waites Modified over 9 years ago
1
Fall 2006 1 EE 333 Lillevik 333f06-l4 University of Portland School of Engineering Computer Organization Lecture 4 Assembly language programming ALU and memory instructions
2
Fall 2006 2 EE 333 Lillevik 333f06-l4 University of Portland School of Engineering MIPS: Programmers View Memory Registers ALU We will design a subset of this computer
3
Fall 2006 3 EE 333 Lillevik 333f06-l4 University of Portland School of Engineering Memory Usage Program Data Stack Memory divided into three separate regions or segments
4
Fall 2006 4 EE 333 Lillevik 333f06-l4 University of Portland School of Engineering Assembly programming Sources files are assembled, then linked This could be compiled
5
Fall 2006 5 EE 333 Lillevik 333f06-l4 University of Portland School of Engineering 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
6
Fall 2006 6 EE 333 Lillevik 333f06-l4 University of Portland School of Engineering 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:
7
Fall 2006 7 EE 333 Lillevik 333f06-l4 University of Portland School of Engineering Memory addresses Notation: c(rx) rx = register/base c = constant/offset Examples 100($t0)# EA = $t0 + 100 0x2f ($22)# EA = $22 + 0x 2f ($sp)# EA = $sp, c = 0
8
Fall 2006 8 EE 333 Lillevik 333f06-l4 University of Portland School of Engineering Directives Provides assembler information Start with dot (.) Examples.text# start text segment.data# start data segment.asciiz # null terminated string.word# insert word data
9
Fall 2006 9 EE 333 Lillevik 333f06-l4 University of Portland School of Engineering A typical line of code label:opCode $destination, $operand1, $operand2, #comment Examples loop: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
10
Fall 2006 10 EE 333 Lillevik 333f06-l4 University of Portland School of Engineering Program Structure Labels Program Directives
11
Fall 2006 11 EE 333 Lillevik 333f06-l4 University of Portland School of Engineering Simple Program
12
Fall 2006 12 EE 333 Lillevik 333f06-l4 University of Portland School of Engineering Let’s run the program
13
Fall 2006 13 EE 333 Lillevik 333f06-l4 University of Portland School of Engineering Write the program? Subtract 3 from 5 and leave in $t2
14
Fall 2006 14 EE 333 Lillevik 333f06-l4 University of Portland School of Engineering Instruction Classes Arithmetic and logic Load Store Comparison Branch and jump Data Movement Floating Point
15
Fall 2006 15 EE 333 Lillevik 333f06-l4 University of Portland School of Engineering Arithmetic and Logic InstructionExampleMeaning addadd $s1, $s2, $s3$s1 = $s2 + $s3 subsub $s1, $s2, $s3$s1 = $s2 - $s3 add immediateaddi $s1, $s2, 100$s1 = $s2 + 100 multiplymult $s2, $s3hi:lo = $s2 x $s3 dividediv $s2, $s3lo = $s2 / $s3 hi = $s2 mod $s3 Only registers used for operands
16
Fall 2006 16 EE 333 Lillevik 333f06-l4 University of Portland School of Engineering Loads (reg mem) InstructionExampleMeaning Load 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 addressla $a0, data$a0 = address of data: Load immediateli $t4, 18$t4 = 0x 12 The point of reference is a register
17
Fall 2006 17 EE 333 Lillevik 333f06-l4 University of Portland School of Engineering Stores (reg mem) InstructionExampleMeaning Store 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
18
Fall 2006 18 EE 333 Lillevik 333f06-l4 University of Portland School of Engineering 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 = var sw $s0, 4($t0) # mem[var + 4] = $s0
19
Fall 2006 19 EE 333 Lillevik 333f06-l4 University of Portland School of Engineering Write the program? NOTE: data movement, mflo $reg
20
Fall 2006 20 EE 333 Lillevik 333f06-l4 University of Portland School of Engineering
21
Fall 2006 21 EE 333 Lillevik 333f06-l4 University of Portland School of Engineering Write the program? Subtract 3 from 5 and leave in $t2
22
Fall 2006 22 EE 333 Lillevik 333f06-l4 University of Portland School of Engineering Write the program?
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.