Arbitrary integer numbers are stored in registers R1, R2 and R3. Find maximum of them and put it into R0.
At first we'll copy maximum of R1 and R2 to R0. Then, if R3>R0, it's necessary to replace R0 value by R3.
Address | Code | Operation | Comments |
---|---|---|---|
0000 | 0412 |
compare R2 and R1 | compare R2 and R1 |
0002 | 3D04 |
if < 0, then pc=pc+4 | to 0008 |
0004 | 0120 |
R2 ==> R0 | remember R2 |
0006 | 1D02 |
pc=pc+2 | to 000A - bypass second branch |
0008 | 0110 |
R1 ==> R0 | remember R1 |
000A | 0403 |
compare R3 with R0 | compare R3 with R0 |
000C | 3D02 |
if < 0, then pc=pc+2 | to 0010 |
000E | 0130 |
R3 ==> R0 | remember R3 |
0010 | 0F00 |
halt | stop |
We can rewrite our program with jump instructions: it will become more demonstrative, but longer. It also will lose relocation properties - we will not be able to move it to anotther address without changes.
Try to input and check this variant of the program yourself.
Address | Code | Operation | Comments |
---|---|---|---|
0000 | 0412 |
compare R2 and R1 |   |
0002 | 3C0D |
if < 0, then to 000C |   |
0006 | 0120 |
R2 ==> R0 | remember R2 |
0008 | 1C0D |
jump to 000E | bypass second branch |
000C | 0110 |
R1 ==> R0 | remember R1 |
000E | 0403 |
compare R3 with R0 |   |
0010 | 3C0D |
if < 0, then to 0016 |   |
0014 | 0130 |
R3 ==> R0 | remember R3 |
0016 | 0F00 |
halt | stop |
Try and examine, how it works in "E97". Don't forget to determine R1-R3 values before running a program.