Presentation is loading. Please wait.

Presentation is loading. Please wait.

Overview Review Trap Instruction Program in LC-3 machine language Use LC-3 Simulator.

Similar presentations


Presentation on theme: "Overview Review Trap Instruction Program in LC-3 machine language Use LC-3 Simulator."— Presentation transcript:

1 Overview Review Trap Instruction Program in LC-3 machine language Use LC-3 Simulator

2 TRAP Calls a service routine, identified by 8-bit “trap vector.” When routine is done, PC is set to the instruction following TRAP. vectorroutine x23input a character from the keyboard x21output a character to the monitor x25halt the program

3 LC-3 Editor / Simulator Go to Authors Web page (http://www.mhhe.com/patt2 )http://www.mhhe.com/patt2 Download LC-3 (LC301.exe) LC-3 Edit LC-3 Simulate Review “Guide to Using the Windows Version of the LC-3 Simulator and LC-3 Edit”

4 Example AddressInstructionComments x30F61 1 1 0 0 0 1 1 1 1 1 1 1 1 0 1 R1  PC – 3 = x30F4 x30F70 0 0 1 0 1 0 0 0 1 1 0 1 1 1 0 R2  R1 + 14 = x3102 x30F80 0 1 1 0 1 0 1 1 1 1 1 1 0 1 1 M[PC - 5]  R2 M[x30F4]  x3102 x30F90 1 0 1 0 1 0 0 1 0 1 0 0 0 0 0 R2  0 x30FA0 0 0 1 0 1 0 0 1 0 1 0 0 1 0 1 R2  R2 + 5 = 5 x30FB0 1 1 1 0 1 0 0 0 1 0 0 1 1 1 0 M[R1+14]  R2 M[x3102]  5 x30FC1 0 1 0 0 1 1 1 1 1 1 1 0 1 1 1 R3  M[M[x30F4]] R3  M[x3102] R3  5 Opcode

5 Example 1: Multiply This program multiplies two unsigned integers in R4 and R5. clear R2 add R4 to R2 decrement R5 R5 = 0? HALT No Yes Write program

6 x3200 Clear Accumulator (R2)R2 <- 0 x3201 Add [R4] to AccumulatorR2 <- R2 + R4 x3202 Dec R5R5 <- R5 – 1 x3203 Do again if [R5] > 0BR p x3201 x3204 StopHALT Program to multiply [R4] x [R5] and place result in R2

7 Write program Program to multiply [R4] x [R5] and place result in R2

8 x3200 Clear Accumulator (R2)R2 <- 00101 010 010 1 00000 54A0 x3201 Add [R4] to AccumulatorR2 <- R2 + R4 0001 010 010 0 00 100 1484 x3202 Dec R5R5 <- R5 – 10001 101 101 1 11111 1B7F x3203 Do again if [R5] > 0BR p x32010000 011 111111101 07FD x3204 StopHALT1111 0000 00100101 F025 Program to multiply [R4] x [R5] and place result in R2 Test on Simulator

9 Example 2 Compute sum of 12 integers. Numbers start at location x3100. Program starts at location x3000. R1  x3100 R3  0 (Sum) R2  12(count) R2=0? R4  M[R1] R3  R3+R4 R1  R1+1 R2  R2-1 NO YES Write program

10 Example 2 – Sum integers form x3100 – x310B AddressInstructionComments x30001 1 1 0 0 0 1 1 0 0 0 0 0 0 0 0 R1  x3100 x30010 1 0 1 0 1 1 0 1 1 1 0 0 0 0 0 R3  0 x30020 1 0 1 0 1 0 0 1 0 1 0 0 0 0 0 R2  0 x30030 0 0 1 0 1 0 0 1 1 1 0 1 1 0 0 R2  12 x30040 0 0 0 0 1 0 0 0 0 0 0 1 0 0 1If Z, goto x3009 x30050 1 1 0 1 0 0 0 0 1 0 0 0 0 0 0Load next value to R4 x30060 0 0 1 0 1 1 0 1 1 0 0 0 0 0 1Add to R3 x30070 0 0 1 0 0 1 0 0 1 1 0 0 0 0 1Increment R1 (pointer) X30080 0 0 1 0 1 0 0 1 0 1 1 1 1 1 1Decrement R2 (counter) x30090 0 0 0 1 1 1 0 0 0 0 0 0 1 0 0Goto x3004

11 Write a program to place the absolute value of the [R2] in R2 Sample program 4

12 Example 3 - # Occurrences of Inputted Char

13 Example 3 - # Occurrences of Inputted Char Program (1 of 2) AddressInstructionComments x30000 1 0 1 0 1 0 0 1 0 1 0 0 0 0 0 R2  0 (counter) x30010 0 1 0 0 1 1 0 0 0 0 1 0 0 1 0 R3  M[x3102] (ptr) x30021 1 1 1 0 0 0 0 0 0 1 0 0 0 1 1Input to R0 (TRAP x23) x30030 1 1 0 0 0 1 0 1 1 0 0 0 0 0 0 R1  M[R3] x30040 0 0 1 1 0 0 0 0 1 1 1 1 1 0 0 R4  R1 – 4 (EOT) x30050 0 0 0 0 1 0 0 0 0 0 0 1 1 1 0If Z, goto x300E x30061 0 0 1 0 0 1 0 0 1 1 1 1 1 1 1 R1  NOT R1 x30070 0 0 1 0 0 1 0 0 1 1 0 0 0 0 1 R1  R1 + 1 X30080 0 0 1 0 0 1 0 0 1 0 0 0 0 0 0 R1  R1 + R0 x30090 0 0 0 1 0 1 0 0 0 0 0 1 0 1 1If N or P, goto x300B

14 Example 3 - # Occurrences of Inputted Char Program (2 of 2) AddressInstructionComments x300A0 0 0 1 0 1 0 0 1 0 1 0 0 0 0 1 R2  R2 + 1 x300B0 0 0 1 0 1 1 0 1 1 1 0 0 0 0 1 R3  R3 + 1 x300C0 1 1 0 0 0 1 0 1 1 0 0 0 0 0 0 R1  M[R3] x300D0 0 0 0 1 1 1 0 0 0 0 0 0 1 0 0Goto x3004 x300E0 0 1 0 0 0 0 0 0 0 0 1 0 0 1 1 R0  M[x3013] x300F0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 R0  R0 + R2 x30101 1 1 1 0 0 0 0 0 0 1 0 0 0 0 1Print R0 (TRAP x21) x30111 1 1 1 0 0 0 0 0 0 1 0 0 1 0 1HALT (TRAP x25) X3012Starting Address of File x30130 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0ASCII x30 (‘0’)

15 Program to display absolute value of number in R2 (-99 >= [R2] >= 99) Write program

16 Program to display absolute value of number in R2 (-99 >= [R2] >= 99) Find absolute value ADD R2, R2, #0 ; set cc14A0 BRzp +20602 NOT R2, R294BF ADD R2, R2, #114A1 R5 will contain x30 (#48), the offset for ASCII numbers AND R5, R5, #05B60 ADD R5, R5, #151B6F ADD R5, R5, #31B63 Check for [R2] >9 AND R4, R4, #0 ; init high digit holder to zero5920 ADD R2, R2, #-1014B6 BRn +20802 ADD R4, R4, #11921 BR -40FFC ADD R3, R2, #10 ; save low digit16AA If high digit = 0, don't display it ADD R4, R4, #0 ; set CC1920 BRz +20402 Display high digit ADD R0, R4, R51105 TRAP x21F021 Display low digit Add R0, R3, R510C5 TRAP x21F021 Halt TRAP x25F025


Download ppt "Overview Review Trap Instruction Program in LC-3 machine language Use LC-3 Simulator."

Similar presentations


Ads by Google