Integer comparison: Difference between revisions

Added Computer/zero Assembly
(Added Computer/zero Assembly)
Line 636:
Then, execute the function for better control:
(compare-integers)
 
=={{header|Computer/zero Assembly}}==
The only conditional instruction we have is <tt>BRZ</tt> (branch on accumulator zero). We can therefore test for equality very quickly. To test for "greater than" or "less than", however, requires a loop.
 
If you run this program, it will halt awaiting user input. Toggle in the value of <math>x</math>, then click <tt>Enter</tt>, then toggle in <math>y</math>, then <tt>Enter</tt>, and then <tt>Run</tt>. <math>x</math> and <math>y</math> must both be unsigned eight-bit integers. The computer will halt with the accumulator storing 1 if <math>x</math>><math>y</math>, 0 if <math>x</math>=<math>y</math>, or -1 if <math>x</math><<math>y</math>; and it will be ready for a fresh pair of integers to be entered.
<lang czasm>start: STP ; get input
 
x: NOP
y: NOP
 
LDA x
SUB y
BRZ start ; x=y, A=0
 
loop: LDA x
SUB one
BRZ x<y
STA x
 
LDA y
SUB one
BRZ x>y
STA y
 
JMP loop
 
x>y: LDA one ; A := 1
JMP start
 
x<y: SUB one ; A := 0-1
JMP start
 
one: 1</lang>
 
=={{header|D}}==
519

edits