Sarajevo School of Science and Technology Course: CS130, Fall 2005. Assignment #3: given Dec 20, due Tuesday Dec 27, 2005, 3:00 PM. Show your answers in the space below question. Copying and mess will be punished. Question 1 The PC contains x3010. The following memory locations contain values as shown: x3050: x70A4 x70A2: x70A3 x70A3: xFFFF x70A4: x123B The following three instructions are then executed. x3010 1110 0110 0011 1111 LEA R3, x3F x3011 0110 1000 1100 0000 LDR R4, R3, #0 x3012 0110 1101 0000 0000 LDR R6, R4, #0 ; R3 <- x3050 ; R4 <- x70A4 ; R6 <- x123B a. What is the content of R6 register? (10 points) x123B b. Replace three above instructions with the single one with the same effect. (10 points) LDI R6, x3F; 1010 1100 00111111 ; R6 <- M[M[x3050] = M[x70A4] = x123B c. What is a difference between this question and textbook problem 5.22? (5 points) x3010 LEA R6, x3F ; R6 <- x3050 x3011 LDR R4, R3, #0 ; R4 <- ???? x3012 LDR R6, R4, #0 ; R6 <- ???? Question 2 Problem 6.15: Below are register and memory contents before and after the instruction at x3010 is executed. Indicate the instruction in mnemonic and binary format. (10 points) register R0: R1 R2 R3 R4 R5 R6 R7 x3010 before x3208 x2D7C xE373 x2053 x33FF xF4A2 x5220 x3208 after x3208 x2D7C xE373 x2053 x33FF xF4A2 x5220 x3208 STR R2, R4, #7 memory x3400 x3401 x3402 x3403 x3404 x3405 x3406 x3407 before x3001 x7A00 x7A2B xA700 xF011 x2003 x31BA xC100 after x3001 x7A00 x7A2B xA700 xF011 x2003 xE373 xC100 x3010 0111 010 100 000111 ; M[R4 + 7] <- R2 Question 3 Problem 9.4: Consider the following LC-3 program: .ORIG x3000 L1 LEA R1, L1 AND R2, R2, x0 ADD R2, R2, x2 LD R3, P1 L2 LDR R0, R1, xC OUT ADD R3, R3, #-1 BRz GLUE ADD R1, R1, R2 BR L2 GLUE HALT P1 .FILL xA .STRINGZ "Ixnasetfrvujchtio!r" .END a. After this program is assembled and loaded what binary pattern is stored in memory location x3005? (5 points) TRAP x21 = 1111 0000 0010 0001 b. Which instruction (provide memory address) is executed after instruction x3005 is executed? (10 points) x0430 ST R1, SaveR1 ; 0011 001 000000111 c. Which instruction (provide memory address) is executed prior to instruction x3006? (5 points) x0435 RET ; 1100 000 111 000000 d. What is the output of this program? (5 points) Instructor Question 4 Write an LC-3 assembly program that will take your full name as an input up to 30 characters and after you hit “return” ‘0A’ it will echo your name to the console followed by “the Great”. For instance when I hit return after typing Dino Melin, the program will print: Dino Melin the Great. (30 points) You have to show your program working to the Teaching Assistant to get points. You can use TRAPS x20 and x22 as well. Question 5 Problem 10.3: Push Rn pushes Register n onto stack, POP Rn removes a value from the stack and loads it into Rn. Figure below shows a snapshot of the eight registers of the LC-3 before and after the following six stack operations are performed. Identify (a) – (d). (10 points). Before After R0 x0000 PUSH R4 R0 x1111 PUSH R4 R1 x1111 PUSH (a) R1 x1111 PUSH R1 R2 x2222 POP (b) R2 x3333 POP R0 R3 x3333 PUSH (c) R3 x3333 PUSH R3 R4 x4444 POP R2 R4 x4444 POP R2 R5 x5555 POP (d) R5 x5555 POP R7 R6 x6666 R6 x6666 R7 x7777 R7 x4444