220 likes | 384 Views
Computer Organization Lecture 4. Assembly language programming ALU and memory instructions. Memory. Registers. ALU. MIPS: Programmers View. We will design a subset of this computer. Stack. Data. Program. Memory Usage. Memory divided into three separate regions or segments.
E N D
Computer OrganizationLecture 4 Assembly language programming ALU and memory instructions University of Portland School of Engineering
Memory Registers ALU MIPS: Programmers View We will design a subset of this computer University of Portland School of Engineering
Stack Data Program Memory Usage Memory divided into three separate regions or segments University of Portland School of Engineering
Assembly programming This could be compiled Sources files are assembled, then linked 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: OSwrites program into memory, transfers control, program runs, control returns to OS 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: 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 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 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 University of Portland School of Engineering
Program Directives Labels Program Structure University of Portland School of Engineering
Simple Program University of Portland School of Engineering
Let’s run the program University of Portland School of Engineering
Write the program? Subtract 3 from 5 and leave in $t2 University of Portland School of Engineering
Instruction Classes • Arithmetic and logic • Load • Store • Comparison • Branch and jump • Data Movement • Floating Point University of Portland School of Engineering
Arithmetic and Logic Only registers used for operands University of Portland School of Engineering
Loads (reg mem) The point of reference is a register University of Portland School of Engineering
Stores (reg mem) The point of reference is a register 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 University of Portland School of Engineering
Write the program? NOTE: data movement, mflo $reg University of Portland School of Engineering
Write the program? Subtract 3 from 5 and leave in $t2 University of Portland School of Engineering
Write the program? University of Portland School of Engineering