"E97": example of branch program

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.

AddressCodeOperationComments
00000412 compare R2 and R1compare R2 and R1
00023D04 if < 0, then pc=pc+4to 0008
00040120 R2 ==> R0 remember R2
00061D02 pc=pc+2 to 000A - bypass second branch
00080110 R1 ==> R0 remember R1
000A0403 compare R3 with R0compare R3 with R0
000C3D02 if < 0, then pc=pc+2to 0010
000E0130 R3 ==> R0 remember R3
00100F00 haltstop

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.

AddressCodeOperationComments
00000412 compare R2 and R1 
0002
0004
3C0D
000C
if < 0, then to 000C  
00060120 R2 ==> R0 remember R2
0008
000A
1C0D
000E
jump to 000E bypass second branch
000C0110 R1 ==> R0 remember R1
000E0403 compare R3 with R0  
0010
0012
3C0D
0016
if < 0, then to 0016  
00140130 R3 ==> R0 remember R3
00160F00 haltstop

Try and examine, how it works in "E97". Don't forget to determine R1-R3 values before running a program.

Back to main applet page
1