Class Notes (834,634)
Canada (508,661)
CSC258H1 (46)
Lecture

mar25ce.docx

1 Page
90 Views
Unlock Document

Department
Computer Science
Course
CSC258H1
Professor
Steve Engels
Semester
Winter

Description
 Week 10 review Q5 (from 2011/2012 Winter Part D Q3)  Intracting with Memory o Wirte a short assembly language program that is a translation of o All programs needs to fetch values from memory into registers, program on the right. You can assume that i has been placed on top operate on them, then store the values back into memory of the stack and that the return value should be placed on the stackmory operations are i-type, with the following form as well before returning to the calling program. o sign In C 1. int sign (int i) { 2. if (i > 0) { 3. return 1; 4. } else if (i < 0) { o Load & Store instructions 5. return -1;  i is an offset, usually zero; used for when multiple values are 6. } else { needed from a given memory location 7. return 0; 8. }  for arrays i is used to extract values not at the front of 9. } the arrays pointer to array stored at register $s is the pointer to the first element o sign in Assembly 1. # register usage: $t0=i, $v0=ret_val  for objects, pointer to the start of the object’s block of 2. SIGN: addi $sp, $sp, 4 # move $sp down memory stored at register $s, use i to traverse object  or for stack parameters 3. lw $t0, 0($sp) # access $sp 4. bgtz $t0, POS # branch if (i > 0)  The address in memory needed for load/store is in register $s 5. beq $t0, $zero, EQ # branch if (i == 0)  b = byte = 1 byte = 8bits -ex. characters 6. NEG: addi $v0, $zero, -1 # (i < 0): $v0 = -1  h = halfword = 2 bytes = 16bits 7. j END  w = word = 4 bytes = 32bits -ex. instructions, ints 8. POS: addi $v0, $zero, 1 # (i > 0): $v0 = 1 9. j END  l = load; s = store 10. EQ: add $v0, $zero, $zero # (i == 0): $v0 = 0  Note: load bytes/halfwords into 32bit registers, end up with 11. END: sw $v0, 0($sp) # store $v0 to $sp extra spaces 12. addi $sp, $sp, -4 # move $sp back up 13. jr $ra # jump to $ra, exit  If u suffix, pad extra space with zeros (logical)  Else treat like signed integer and sign extend it (arithmetic) o Note, this will cause an infinite loop: take the PC store it in Instruction Opcode/ Synatx Operation END: j END Function o Stack, all programs have access to it lb 100000 $t, i($s) $t = SE(MEM [$s+i]:1)  Stackpointer ($sp) points to first available spot in stack  b/c to account for empty stack case lbu 100100 $t, i($s) $t = ZE(MEM [$s+i]:1)  For obtaining values to work with, and returning values lh 100001 $t, i($s) $t = SE(MEM [$s+i]:2)  store variables that needs to be communicated to other lhu 100101 $t, i($s) $t = ZE(MEM [$s+i]:2) programs lw 100011 $t, i($s) $t = MEM[$s+i]:4  most of time passing value through stack b/c large
More Less

Related notes for CSC258H1

Log In


OR

Join OneClass

Access over 10 million pages of study
documents for 1.3 million courses.

Sign up

Join to view


OR

By registering, I agree to the Terms and Privacy Policies
Already have an account?
Just a few more details

So we can recommend you notes for your school.

Reset Password

Please enter below the email address you registered with and we will send you a link to reset your password.

Add your courses

Get notes from the top students in your class.


Submit