1 / 15

COMPSCI 210 Semester 1 - 2014

COMPSCI 210 Semester 1 - 2014. Tutorial 6 – Revision. Solution – Exercise 5.13. ADD R3, R2, #0 NOT R3, R3 ADD R3, R3, #1 ADD R1, R2, R3 (c) ADD R1, R1, #0. (e) AND R2, R2, #0. Exercise 6.a. Write LC-3 programmes to perform the following Operations :

Download Presentation

COMPSCI 210 Semester 1 - 2014

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. COMPSCI 210Semester 1 - 2014 Tutorial 6 – Revision

  2. Solution – Exercise 5.13 ADD R3, R2, #0 NOT R3, R3 ADD R3, R3, #1 ADD R1, R2, R3 (c) ADD R1, R1, #0 (e) AND R2, R2, #0

  3. Exercise 6.a Write LC-3 programmes to perform the following Operations : Subtraction  5 - 3 Multiplication  5 X 4

  4. Solution – Exercise 6.a( 5 - 3 ) .ORIG x3000 ; subtract #5 - #3 LD R1, FIRST_NUMBER LD R2, SECOND_NUMBER ; create the negative of R2 NOT R2, R2 ADD R2, R2, #1 ; subtract - R3 now holds #2 ADD R3, R1, R2 HALT FIRST_NUMBER .fill #5 SECOND_NUMBER .fill #3 .END

  5. Solution – Exercise 6.a(5 X 4) LD R1, FIRST_NUMBER LD R2, COUNTER ; enter loop MULTIPLY ADD R1, R1, R1 ; add to sum ADD R2, R2, #-1 ; decrement our counter BRpMULTIPLY ; continue until the counter num is 0 HALT FIRST_NUMBER.FILL #5 COUNTER .FILL #2 .END

  6. Exercise 6.b Write an LC-3 programme to perform the following : if (a == b) { //do something1 } else { //do something2 }

  7. Solution – Exercise 6.b ;variable 'a' is in R1  ;variable 'b' is in R2  ;subtract a from b, if it is 0 they are equal  ;negate R2 and store it in R0 NOT R0, R2 ADD R0, R0, #1  ADD R0, R1, R0  ;subtract a from b BRnpELSE ;if they are not 0, go to the else block;do something1 BRnzpEND ELSE ;do something2  END: 

  8. Solution – Exercise 5.23 ( LEA R1, #1 ) ( LDR R2, R1, #2 ) ( TRAP 0x25 )

  9. Solution – Exercise 5.25 • NOT R4, R3 • ADD R4, R4, #1 • ADD R1, R4, R2 • BRz Done • BRn Reg3 • BRp Reg2 • Reg3 ADD R1, R3, #0 • BRnzp Done • Reg2 ADD R1, R2, #0 • Done TRAP 0x25

  10. What is the equivalent instruction for HALT ?

  11. Solution – Exercise 7.9 TRAP 0x25 has the same effect as using HALT

More Related