Docsity

Programming in Machine Language - Machine Organization - Lecture Slides, Slides of Electric Machines

Partial preview of the text

Download Programming in Machine Language - Machine Organization - Lecture Slides and more Slides Electric Machines in PDF only on Docsity!

Chapter 6

• Programming in Machine Language

• The LC-3 Simulator

• The LC-3 Editor

The LC-3 Computer a von Neumann machine Memory PSW (Program Status Word): Bits: 15 10 9 8 2 1 0 | S| |Priority| | N| Z| P| PSW Fetch: Next Instruction from Memory (PC)  (points to) next instruction PC (PC) + 1 Decode: Fetched Instruction Evaluate: Instr & Address (es) (find where the data is) Load: Operand (s) (get data as specified) Execute: Operation Store: Result (if specified) The Instruction Cycle:

LC-3 Memory Map

(64K of 1 6 bit words ) 256 words 256 words (We will get to these later) 23.5 K words 39.5 K words 512 words

LC-3 Instructions Addressing Modes

  • Register (Operand is in one of the 8 registers)
  • PC-relative (Operand is “offset” from where the PC points - offsets are sign extended to 16 bits)
  • Base + Offset (Base relative) (Operand is “offset” from the contents of a register)
  • Immediate (Operand isin the instruction)
  • Indirect (The “Operand”points to the real address of Operand - rather than being the operand) Note: The LC-3 has No Direct Addressing Mode Docsity.com

Data Movement Instructions

  • Load - read data from memory to a register
    • LD: PC-relative mode [0010 DR PCoffset9]
    • LDI: Indirect mode [1010 DR PCoffset9]
    • LDR: Base+offset mode [0110 DR BaseR offset6]
  • Store - write data from a register to memory
    • ST: PC-relative mode [0011 DR PCoffset9]
    • STI: Indirect mode [1011 DR PCoffset9]
    • STR: Base+offset mode [0111 DR BaseR offset6]
  • Load effective address – address saved in register
    • LEA: PC-relative mode [1110 DR PCoffset9] All have 2 or 3 operands

Control Instructions

  • Go to New Location in Program – “GO TO”
    • BR: PC-relative mode [0000 NZP PCoffset9]
    • JMP: Indirect mode [1100 000 BaseR 000000]
  • Trap Service Routine Call
    • TRAP: Indirect [1111 0000 TrapVec8]
  • Jump to Subroutine (will be covered later)
    • JSR: PC-relative mode [0100 1 PCoffset11]
    • JSRR: Indirect mode [0100 000 BaseR 000000]
  • Return from Trap/Subroutine
    • RET: No operand [1100 000 111 000000]
  • Return from Interrupt (will be covered later)
    • RTI: No operand [1000 000000000000]

TRAPS See page 543.

Example: Program to multiply [R4] x [R5] and place the result in R clear R add R4 to R decrement R R5 = 0? HALT No Yes R4 – Multiplicand R5 – Multiplier R2 – Accumulator

x3200?

clear R add R4 to R decrement R R5 = 0? HALT No Yes

R2 <- 0

R2 <- R2 + R

R5 <- R5 – 1

BRz x

HALT

Example: Program to multiply [R4] x [R5] and place the result in R

x3200 0101010010100000

x3201 0001010010000100

x3202 0001101101111111

x3203 0000010111111101

x3204 1111000000100101

clear R add R4 to R decrement R R5 = 0? HALT No Yes

R2 <- 0

R2 <- R2 + R

R5 <- R5 – 1

BRz x

HALT

Example: Program to multiply [R4] x [R5] and place the result in R

LC3 Editor / Simulator Go to Author’s Web Site: http://www.mhhe.com/patt Get:

  • LC3 Edit
  • LC3 Simulator

LC3 Edit Screen

LC-3 Simulator Screen

LC-3 Simulator Open LC-3 Simulator

  • Load prog.obj - Load data.obj
    • Set breakpoint(s) or
    • Step through program