{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Assignment #6 solutions Page 4

Assignment #6 solutions Page 4 - CS 3101 Spring 2007...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CS 3101! Spring 2007 3111121) 2 AND no, R0, 0 ADD RD, RD, -1 The first branch is taken since the P condition code is set. which sets the PC to the second AND instruction. The resulting condition codes are N=1, Z=U, P=0. 9. The disassembled program is shown below. The addresses of the instructions are also shown. assuming the program is loaded at x3000. : menstruation m—‘H- ”—— r3=mem-I This program loops three times, accumulating the numbers stored in memory into register r4. First, :3 is loaded with r0010 (from location 13008), and its value is added to r4 that holds our sum (which is initisz sero). Thee, I2 is incremented, so that I3 is loaded with x0020 (from x3009), and its value added to r4 during the second iteration of the loop. Then :2 is incremented again, so IE is loaded with x0030 (from x3OUA), and its value is added to r4 in the third iteration of the loop. Then r2 is incremented, so r3 is loaded with 350000 (from 130013). Since this value is zero, the first branch will redirect the PC to x3007 which halts the program. So at the end, :4 holds x0010 + 10020 + x0030 which is x0060 or 96 in base 10. 10. An LC-3 program to place the decimal value 721 into register 32 using only ADD instructions. .ORIG x5000 ; directive: put code at start or user mmry 1.1) no. Zero : Zero out the initial register 11313112, 110. #15 :R2=15 ADD”.R2.R2 ;R2-R2+B2=30 ADDRZ.R2.R2 ;l12=|12+ll2=60 ADDB2.RZ,R2 3R2=R2+RZ=120 ADDM.R2,B2 3112-32+R2-240 mono,n2,n2 :RO-RQ+32=4BO ADDRZ,B.0.R2 ;32=R0+32=480+240=720 ADDR2,I12.#1 ;m-n2+1-721 EALT : Memory 1111: Zero .FILI. 20000 ; Zero to initialize registers .EHD ; directive: no more code 11. (a) An LC—3 program to multiply two arbitrary positive numbers by repeated addition. Operands are specified at labels opi and op2 in memory and the result is placed back in memory at label Result. Para. 4 of 5 W ...
View Full Document

{[ snackBarMessage ]}