






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Notes; Class: COMPUTER ORGNIZATN; Subject: Computer Science; University: University of Maryland; Term: Fall 2003;
Typology: Study notes
1 / 11
This page cannot be seen from the preview
Don't miss anything!







Machine language: very low level Assembler: provides higher-level language for convenience in programming Register mnemonics We've already used them. The real machine deals in register numbers (0-31). Only $0 and $31 are special in the hardware. Other registers are used for particular purposes by software convention. Pseudoinstructions Instructions or formats which are not directly implemented in the hardware. CISC would include many alternative forms of instructions. Large and slow instruction sets Pseudoinstruction may be translated to 1 or more real instructions. Pseudocomputer: more flexible than real computer, easier to program Another layer of abstraction Labels Can use identifiers (names) to represent locations in the program Assembler calculates necessary offsets Directives Control layout and processing of program
Instruction Real instructions Semantics Copy contents of register s to register t mov $rt, $rs addi $rt, $rs, 0 R[t] = R[s]
Load immediate into register s li $rs, immed R[s] = immed The way this is translated depends on whether immed is 16 bits or 32 bits: li $rs, small ori $rs, $0, small R[s] = small li $rs, -small addiu $rs, $0, -small R[s] = -small li $rs, big lui $rs, upper(big) R[s] = big ori $rs, $rs, lower(big) small: 16-bit value big: 32-bit value Note: upper(big) and lower(big) are not real instruction syntax The assembler must figure out how to get the upper 16 bits of a 32-bit value: upper (big) = big (^) 31-16 lower (big) = big (^) 15-
Load address into register s la $rs, addr lui $rs, upper(addr) R[s] = addr ori $rs, $rs, lower(addr)
How do we compare values in 2 registers? Instructions for beq, bne , but not for general relational operators result slt $rd, $rs, $rt R[s] < R[t] 1 R[s] >= R[t] 0
Instruction Real instructions Semantics
bge $rs, $rt, LABEL slt $at, $rs, $rt if (R[s] >= R[t]) beq $at, $zero, LABEL goto LABEL bgt $rs, $rt, LABEL slt $at, $rt, $rs if (R[s] > R[t]) bne $at, $zero, LABEL goto LABEL ble $rs, $rt, LABEL slt $at, $rt, $rs if (R[s] <= R[t]) beq $at, $zero, LABEL goto LABEL blt $rs, $rt, LABEL slt $at, $rs, $rt if (R[s] < R[t]) bne $at, $zero, LABEL goto LABEL
Note that LABEL must be converted to an offset from PC
What about immediate value? bge $rs, immed, LABEL
Comparison to 0
Instruction Real instructions Semantics beqz $rs, LABEL beq $rs,$zero,label if (R[s] == 0) goto LABEL bnez $rs, LABEL bne $rs,$zero,label if (R[s] != 0) goto LABEL
Instruction Real instructions Semantics
Set if equal: seq $rd, $rs, $rt andi $rd, $rd, 0 # R[d] = (R[s] == R[t])? 1 : 0 bne $rs, $rt, next ori $rd, $zero, 1 next: What's wrong with this? Better way: xor $rd, $rs, $rt # R[d] = ~(R[s] == R[t]) sltiu $rd, $rd, 1 # R[d] = (R[d] < 1) Set if not equal: sne $rd, $rs, $rt # R[d] = (R[s] != R[t])? 1 : 0 xor $rd, $rs, $rt # R[d] = ~(R[s] == R[t]) sltu $rd, $0, $rd # R[d] = (R[d] > 0) Set if greater than or equal: sge $rd, $rs, $rt # R[d] = (R[s] >= R[t])? 1 : 0 slt $rd, $rs, $rt # R[d] = (R[s] < R[t])? 1 : 0 xori $rd, $rd, 1 # R[d] = ~R[d] Other combinations, including unsigned: sgeu, sgt, sgtu, sle, sleu
Instruction Real instructions Semantics not $rd, $rs addi $at, $0, -1 # R[1] = - xor $rd, $rs, $at # R[d] = R[s] ^ R[1] Better way: not $rd, $rs nor $rd, $rs, $0 # R[d] = ~R[s]
Why does this work? a b a | b ~(a|b) ~(0|b) ~b 0 0 0 1 1 1 0 1 1 0 0 0 1 0 1 0 1 1 1 0
.text .globl main
main: ori $8,$0,0x2 # put two's comp. two into register 8 ori $9,$0,0x3 # put two's comp. three into register 9 addu $10,$8,$9 # add register 8 and 9, put result in 10
Directives .text defines beginning of source code .globl identifies global label Label (symbolic address) main Defining data .data # defines beginning of data area arr: .word 2, 4, 6 # defines array of 3 words (int) chr: .byte 65 # defines 1 byte (char) str: .asciiz "a string" # defines a C-type character string
This document was created with Win2PDF available at http://www.daneprairie.com. The unregistered version of Win2PDF is for evaluation or non-commercial use only.