Programming

Systematic Decomposition

Programming Constructs:

  1. Sequential
  2. Conditional
  3. Iterative

Debugging

  • %exe
  • %pc LOCATION, followed by %step

But that can be tedious if you need to step through 10,000 instructions. Therefore, we introduce the idea of a breakpoint.

%help - shows the following:

 %bp [clear | SUSPENDHEX]           - show, clear, or set breakpoints
 %cont                              - continue running
 %dis [STARTHEX [STOPHEX]]          - dump memory as program
 %dump [STARTHEX [STOPHEX]]         - list memory in hex
 %exe                               - execute the program
 %mem HEXLOCATION HEXVALUE          - set memory
 %pc HEXVALUE                       - set PC
 %reg REG HEXVALUE                  - set register REG to HEXVALUE
 %regs                              - show registers
 %reset                             - reset LC3 to start state
 %step                              - execute the next instruction, increment PC
In [40]:
%bp
    No breakpoints set

Example 3

Page 168.

Some data:

In [48]:
.ORIG x3100
0000 0000 0000 0001
0000 0000 0000 0010
1000 0000 0000 0100
0000 0000 0000 0101
0000 0000 0000 1000
0000 0000 0001 0000
0000 0000 0010 0000
0000 0000 0100 0000
0000 0000 1000 0000
0000 0001 0000 0000
.END
Assembled! Use %dis or %dump to examine; use %exe to run.

The program from Figure 6.7:

In [49]:
.ORIG x3000
0101000000100000
0001000000100001
0101001001100000
0001001001111011
0101011011100000
0001011011101010
0010100000001001
0110010100000000
0001010010000001
0000010000000101
0001100100100001
0001011011111111
0110010100000000
0000001111111010
0101000000100000
1111000000100101
0011000100000000
.END
Assembled! Use %dis or %dump to examine; use %exe to run.
In [50]:
%exe
============================================================
Computation completed
============================================================
Instructions: 22
Cycles: 148 (0.000074 milliseconds)

============================================================
Registers:
============================================================
PC: x048E
N: 0 Z: 1 P: 0 
R0: x0000 R1: xFFFB R2: x8004 R3: x0008 
R4: x3102 R5: x0000 R6: x0000 R7: x3010 
In [51]:
%bp x300D
============================================================
Breakpoints
============================================================
    1)            x300D: x03FA
In [52]:
%exe
...breakpoint hit at x300D
============================================================
Computation SUSPENDED
============================================================
Instructions: 13
Cycles: 88 (0.000044 milliseconds)

============================================================
Registers:
============================================================
PC: x300D
N: 0 Z: 0 P: 1 
R0: x0001 R1: xFFFB R2: x0002 R3: x0009 
R4: x3101 R5: x0000 R6: x0000 R7: x0000 
In [53]:
%cont
...breakpoint hit at x300D
============================================================
Computation SUSPENDED
============================================================
Instructions: 19
Cycles: 127 (0.000063 milliseconds)

============================================================
Registers:
============================================================
PC: x300D
N: 1 Z: 0 P: 0 
R0: x0001 R1: xFFFB R2: x8004 R3: x0008 
R4: x3102 R5: x0000 R6: x0000 R7: x0000 
In [54]:
%cont
============================================================
Computation completed
============================================================
Instructions: 22
Cycles: 148 (0.000074 milliseconds)

============================================================
Registers:
============================================================
PC: x048E
N: 0 Z: 1 P: 0 
R0: x0000 R1: xFFFB R2: x8004 R3: x0008 
R4: x3102 R5: x0000 R6: x0000 R7: x3010 
In [ ]:
%bp clear
In [ ]:
%cont