Fall EE 333 Lillevik 333f06-l4 University of Portland School of Engineering Computer Organization Lecture 4 Assembly language programming ALU and memory instructions
Fall 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
Fall EE 333 Lillevik 333f06-l4 University of Portland School of Engineering Memory Usage Program Data Stack Memory divided into three separate regions or segments
Fall EE 333 Lillevik 333f06-l4 University of Portland School of Engineering Assembly programming Sources files are assembled, then linked This could be compiled
Fall 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
Fall 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:
Fall 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 = $t x2f ($22)# EA = $22 + 0x 2f ($sp)# EA = $sp, c = 0
Fall 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
Fall 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
Fall EE 333 Lillevik 333f06-l4 University of Portland School of Engineering Program Structure Labels Program Directives
Fall EE 333 Lillevik 333f06-l4 University of Portland School of Engineering Simple Program
Fall EE 333 Lillevik 333f06-l4 University of Portland School of Engineering Let’s run the program
Fall EE 333 Lillevik 333f06-l4 University of Portland School of Engineering Write the program? Subtract 3 from 5 and leave in $t2
Fall 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
Fall 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 = $s multiplymult $s2, $s3hi:lo = $s2 x $s3 dividediv $s2, $s3lo = $s2 / $s3 hi = $s2 mod $s3 Only registers used for operands
Fall 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[$s ] Load byte unsigned (8 bits) lbu $s1, 100($s2)$s1 = mem[$s ] Load addressla $a0, data$a0 = address of data: Load immediateli $t4, 18$t4 = 0x 12 The point of reference is a register
Fall EE 333 Lillevik 333f06-l4 University of Portland School of Engineering Stores (reg mem) InstructionExampleMeaning Store word (32 bits) sw $s1, 100 ($s2)mem[$s ] = $s1 Store byte (8 bits) sb $s1, 100 ($s2)mem[$s ] = $s1 The point of reference is a register
Fall 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
Fall EE 333 Lillevik 333f06-l4 University of Portland School of Engineering Write the program? NOTE: data movement, mflo $reg
Fall EE 333 Lillevik 333f06-l4 University of Portland School of Engineering
Fall EE 333 Lillevik 333f06-l4 University of Portland School of Engineering Write the program? Subtract 3 from 5 and leave in $t2
Fall EE 333 Lillevik 333f06-l4 University of Portland School of Engineering Write the program?