Example Programs

JavaScript Program Assembly Language Program
z = x + y; LOD X
ADD Y
STO Z
HLT
Load contents of memory location 129 (X) into Accumulator
Add contents at address 130 (Y) to Accumulator
Store contents of Accumulator in location 131 (Z)
Halt execution



JavaScript Program Assembly Language Program
z = x*x + y*y; LOD X
MUL X
STO T1
LOD Y
MUL Y
ADD T1
STO Z
HLT
Load contents of memory location 129 (X) into Accumulator
Multiply Accumulator by contents of location 129 (X)
Store contents of Accumulator in temporary location 132 (T1)
Load contents of memory location 130 (Y) into Accumulator
Multiply Accumulator by contents of location 130 (Y)
Add contents at address 132 (T1) to Accumulator
Store contents of Accumulator in location 131 (Z)
Halt execution



JavaScript Program Assembly Language Program
if (x > y) {
  z = 2;
} else {
  z = 3;
}
00: LOD Y
02: SUB X
04: STO T1
06: CPL T1
08: JMZ 16
10: LOD #2
12: STO Z
14: HLT
16: LOD #3
18: STO Z
20: HLT
Load contents of memory location 130 (Y) into Accumulator
Subtract contents of location 129 (X) from Accumulator
Store contents of Accumulator in location 132 (T1)
Test if contents of location 132 (T1) is < 0
Jump to location 16 if location 132 (T1) was not < 0
Load 2 into Accumulator
Store contents of Accumulator in location 131 (Z)
Halt execution
Load 3 into Accumulator
Store contents of Accumulator in location 131 (Z)
Halt execution



JavaScript Program Assembly Language Program
// input in y
x = 0;
while (y > 0) {
  y = y / 10;
  x = x + 1;
}
// output in x
00: LOD #0
02: STO X
04: LOD Y
06: JMZ 20
08: DIV #10
10: STO Y
12: LOD X
14: ADD #1
16: STO X
18: JMP 4
20: HLT
Load 0 into Accumulator
Store contents of Accumulator in location 129 (X)
Load contents of memory location 130 (Y) into Accumulator
Jump to location 20 if Accumulator is 0
Divide Accumulator by 10
Store contents of Accumulator in location 130 (Y)
Load contents of memory location 129 (X) into Accumulator
Add 1 to Accumulator
Store contents of Accumulator in location 129 (X)
Jump to location 4
Halt execution