Presentation is loading. Please wait.

Presentation is loading. Please wait.

Overview Program in LC-3 machine language Use the Editor

Similar presentations


Presentation on theme: "Overview Program in LC-3 machine language Use the Editor"— Presentation transcript:

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

2 LC-3 Editor / Simulator Go to Authors’ Web page: Download:
Download: LC-3 Simulator – Win or Unix - (LC-3 Edit, LC-3 Simulate) LC-3 Simulator Lab Manual

3 Sum of 12 Integers Compute sum of 12 integers.
Numbers start at location x 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

4 Sum integers from x3100 – x310B Address Instruction Comments x3000
R1  x3100 x3001 R3  0 x3002 R2  0 x3003 R2  12 x3004 If Z, goto x300A x3005 Load next value to R4 x3006 Add to R3 x3007 Increment R1 (pointer) X3008 Decrement R2 (counter) x3009 Goto x3004

5 The Add program in “binary”
;start x3000 ;R1=x3100 ;R3=0 ;R2=0 ;R2=R2+12 ;If z goto x3009 ;Load next value into R4 ;R3=R3+R4 ;R1=R1+1 ;R2=R2-1 ;goto x3004

6 The Add program in “hex”
3000 ;start x3000 E2FF ;R1=x3100 56E0 ;R3=0 54A0 ;R2=0 14AC ;R2=R2+12 0405 ;If z goto x3009 D840 ;Load next value into R4 16C4 ;R3=R3+R4 1261 ;R1=R1+1 14BF ;R2=R2-1 0FFA ;goto x3004

7 The Add program Data (hex)
3100 ; Begin data at x3100 3107 ; Loc x3100 2819 0110 0310 1110 11B1 0019 0007 0004 0000 0000 ; Loc x310B

8 LC3Edit Load the program into LC3Edit
- Store it as prog.bin for a binary file, or Store it as prog.hex for a hex file - Create a prog.obj file with the Editor Load the data into LCEdit - Store it as data.bin for a binary file, or Store it as data.hex for a hex file - Create a data.obj file with the Editor

9 LC-3 Simulator Open LC-3 Simulator - Load prog.obj - Load data.obj
- Set breakpoint(s) - Step through program

10 TRAP Calls a service routine, identified by 8-bit “trap vector.”
When routine is done, PC is set to the instruction following TRAP. vector routine x23 input a character from the keyboard x21 output a character to the monitor x25 halt the program

11 TRAPS

12 Add HALT to “Add” program
Add HALT statement and run program without breakpoint(s)

13 Example : Multiply Write program to Multiply two unsigned integers in R4 and R5

14 Example : 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

15 Program to multiply [R4] x [R5] and place result in R2
x Clear Accumulator (R2) R2 <- 0 x Add [R4] to Accumulator R2 <- R2 + R4 x Dec R5 R5 <- R5 – 1 x Do again if [R5] > 0 BR p x3201 x Stop HALT

16 Program to multiply [R4] x [R5] and place result in R2
Code program

17 Program to multiply [R4] x [R5] and place result in R2
x Clear Accumulator (R2) R2 < A0 x Add [R4] to Accumulator R2 <- R2 + R x Dec R5 R5 <- R5 – B7F x Do again if [R5] > 0 BR p x FD x Stop HALT F025 Test on Simulator

18 Write a program to place the absolute value of the [R2] in R2
How do we compute A = - A if we don’t have have a subtract instruction?

19 Example - # Occurrences of Inputted Char

20 Example - # Occurrences of Inputted Char Program (1 of 2)
Address Instruction Comments x3000 R2  0 (counter) x3001 R3  M[x3102] (ptr) x3002 Input to R0 (TRAP x23) x3003 R1  M[R3] x3004 R4  R1 – 4 (EOT) x3005 If Z, goto x300E x3006 R1  NOT R1 x3007 R1  R1 + 1 X3008 R1  R1 + R0 x3009 If N or P, goto x300B

21 Example - # Occurrences of Inputted Char Program (2 of 2)
Address Instruction Comments x300A R2  R2 + 1 x300B R3  R3 + 1 x300C R1  M[R3] x300D Goto x3004 x300E R0  M[x3013] x300F R0  R0 + R2 x3010 Print R0 (TRAP x21) x3011 HALT (TRAP x25) X3012 Starting Address of File x3013 ASCII x30 (‘0’)


Download ppt "Overview Program in LC-3 machine language Use the Editor"

Similar presentations


Ads by Google