Professional Documents
Culture Documents
Tutorial 2 Topics Review: What is a symbol table? Problem 1: Create (by hand) a symbol table for these MIPS programs. Problem 2: Assemble this (short) MIPS program that uses labels.
A symbol table is a data structure that stores the name and location of every label in a MIPS program. Important things to remember are: Locations are stored in bytes. There are four bytes per each word/instruction. Your assembler will need to handle MIPS programs with 10,000+ labels, meaning a data structure with fast storing and look-up is essential. Recommended are the Java HashMap or the Scheme hash-table, which oer approximately O(1) operations. The equation for determining which line a label in a beq or bne instruction is: i(L+4) , where L is the current instructions location, and i is the labels 4 location. 3 Problem 1a
Given the following MIPS assembly code, create a symbol table containing all of the labels used. ; Assume program is to be run with mips.twoints ; $1 - first integer ; $2 - second integer
1
lis $3 .word 100 bound: lis $4 .word -100 lis $1 .word bound slt $5, $1, $3 slt $6, $2, $4 beq $5, $0, move bne $6, $0, jump bne $5, $0, leap leap: beq $6, $0, bound shuffle: ; store leaps location in $7
Problem 1b
Given the following MIPS assembly code, create a symbol table containing all of the labels used. ; Assume program is to be run with mips.twoints ; $1 - first integer ; $2 - second integer lis $3 .word 0xFF123 start: next: add $1, $1, $3 sub $3, $3, $1 sw $3, -4($30) lis $4 .word 4 sub $30, $30, $4 lis $5 .word -1 beq $0, $0, skip handleNeg: ; handle negativity mult $3, $5 mflo $3 skip:
; Check if $3 is negative slt $6, $3, $0 bne $6, $0, handleNeg loop:
3
add $3, $3, $5 bne $3, $0, loop end: endplus1: jr $31 6 Problem 1a: Solution
Assemble the following (short) MIPS assembly code into binary, taking into account what values should be substituted in place of the labels. ; Problem 2: Assemble this (short!) MIPS program into binary format. myLittleLabelThatIsOhSoVeryLong: lis $28 .word whyAreAllOfTheseLabelsSoPainfullyLong
bne $0, $0, pleaseEndThis whyAreAllOfTheseLabelsSoPainfullyLong: beq $0, $0, myLittleLabelThatIsOhSoVeryLong pleaseEndThis: ; End program
jr $31 8 Problem 1a: Solution ; ; ; ; ; lis $28 .word whyAreAllOfTheseLabelsSoPainfullyLong bne $0, $0, pleaseEndThis beq $0, $0, myLittleLabelThatIsOhSoVeryLong jr $31