hw4-soln - ECE 209 Homework 4 Fall 2007 1. (15 points)...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
ECE 209 Fall 2007 Homework 4 1. (15 points) Using the given symbol table, write the LC-3 code that corresponds to each of the following C statements. Symbol Type Scope Offset f int local -1 g int global 2 h int* local -4 i int local 0 f = *h & -1; LDR R0, R5, #-4 LDR R0, R0, #0 AND R0, R0, #-1 STR R0, R5, #-1 h = &g; ADD R0, R4, #2 STR R0, R5, #- 4 *h = *h << i - f; LDR R0, R5, #0 LDR R1, R5, #-1 NOT R1, R1 ADD R1, R1, #1 ADD R0, R0, R1 LDR R1, R5, #-4 LDR R1, R1, #0 ADD R0, R0, #0 BRnz DONE L1 ADD R1, R1, R1 ; shift left ADD R0, R0, #-1 ; decr counter BRp L1 DONE LDR R0, R5, #-4 STR R1, R0, #0 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
ECE 209 Fall 2007 Homework 4 2. (20 points) Write the LC-3 code that corresponds to the definition of funTwo below. You must include helpful comments with your code to get full credit. int funOne(char, char*); int funTwo(int a, int *b) { char c, d; c = a & 0xF0; d = (*b + 4) & 0x0F; return (funOne(d, &c) | 0xC0); } funTwo ADD R6, R6, #-1 ; push return val ADD R6, R6, #-1 ; push return address STR R7, R6, #0 ADD R6, R6, #-1 ; push dynamic link STR R5, R6, #0 ADD R5, R6, #-1 ; set frame pointer ADD R6, R6, #- 2 ; local vars LDR R0, R5, #4 ; load a LD R1, C1 ; load constant (0xF0)
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/24/2008 for the course ECE 209 taught by Professor Tuck during the Spring '08 term at N.C. State.

Page1 / 6

hw4-soln - ECE 209 Homework 4 Fall 2007 1. (15 points)...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online