1 / 16

Overview

Overview. Review Trap Instruction Program in LC-3 machine language Use LC-3 Simulator. TRAP. Calls a service routine , identified by 8-bit “trap vector.” When routine is done, PC is set to the instruction following TRAP. LC-3 Editor / Simulator.

Download Presentation

Overview

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. 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.

  3. LC-3 Editor / Simulator • Go to Authors Web page (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 Opcode

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

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

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

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

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

  10. Example 2 – Sum integers form x3100 – x310B

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

  12. Example 3 - # Occurrences of Inputted Char

  13. Example 3 - # Occurrences of Inputted CharProgram (1 of 2)

  14. Example 3 - # Occurrences of Inputted CharProgram (2 of 2)

  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 cc 14A0 • BRzp +2 0602 • NOT R2, R2 94BF • ADD R2, R2, #1 14A1 • R5 will contain x30 (#48), the offset for ASCII numbers • AND R5, R5, #0 5B60 • ADD R5, R5, #15 1B6F • ADD R5, R5, #15 1B6F • ADD R5, R5, #15 1B6F • ADD R5, R5, #3 1B63 • Check for [R2] >9 • AND R4, R4, #0 ; init high digit holder to zero 5920 • ADD R2, R2, #-10 14B6 • BRn +2 0802 • ADD R4, R4, #1 1921 • BR -4 0FFC • ADD R3, R2, #10 ; save low digit 16AA • If high digit = 0, don't display it • ADD R4, R4, #0 ; set CC 1920 • BRz +2 0402 • Display high digit • ADD R0, R4, R5 1105 • TRAP x21 F021 • Display low digit • Add R0, R3, R5 10C5 • TRAP x21 F021 • Halt • TRAP x25 F025

More Related