Integer comparison: Difference between revisions
Content added Content deleted
Puppydrum64 (talk | contribs) |
|||
Line 85: | Line 85: | ||
Done: PLA ;restore Accumulator from stack |
Done: PLA ;restore Accumulator from stack |
||
RTS ;return from subroutine</lang> |
RTS ;return from subroutine</lang> |
||
=={{header|68000 Assembly}}== |
|||
The task of getting input from the user is much more difficult in assembly since it hasn't been done for you unlike nearly all other languages. So that part will be omitted to focus on the actual comparison. |
|||
In assembly, the only difference between a signed integer and an unsigned integer is the comparator(s) used to evaluate it. Therefore we have two different versions of this task. |
|||
===Unsigned Comparison=== |
|||
<lang 68000devpac>Compare: |
|||
;integers to compare are in D0 and D1 |
|||
CMP.L D1,D0 |
|||
BCS .less ;D1 < D0 |
|||
;else, carry clear, which implies greater than or equal to. |
|||
BNE .greater ;D1 > D0 |
|||
;else, d1 = d0 |
|||
LEA Equal,A0 |
|||
JMP PrintString ;and use its RTS to return |
|||
.greater: |
|||
LEA GreaterThan,A0 |
|||
JMP PrintString ;and use its RTS to return |
|||
.less: |
|||
LEA LessThan,A0 |
|||
JMP PrintString ;and use its RTS to return |
|||
LessThan: |
|||
dc.b "second integer less than first",0 |
|||
even |
|||
GreaterThan: |
|||
dc.b "second integer greater than first",0 |
|||
even |
|||
Equal: |
|||
dc.b "both are equal",0 |
|||
even</lang> |
|||
===Signed Comparison=== |
|||
<lang 68000devpac>Compare: |
|||
;integers to compare are in D0 and D1 |
|||
CMP.L D1,D0 |
|||
BLT .less ;D1 < D0 |
|||
;else, carry clear, which implies greater than or equal to. |
|||
BNE .greater ;D1 > D0 |
|||
;else, d1 = d0 |
|||
LEA Equal,A0 |
|||
JMP PrintString ;and use its RTS to return |
|||
.greater: |
|||
LEA GreaterThan,A0 |
|||
JMP PrintString ;and use its RTS to return |
|||
.less: |
|||
LEA LessThan,A0 |
|||
JMP PrintString ;and use its RTS to return |
|||
LessThan: |
|||
dc.b "second integer less than first",0 |
|||
even |
|||
GreaterThan: |
|||
dc.b "second integer greater than first",0 |
|||
even |
|||
Equal: |
|||
dc.b "both are equal",0 |
|||
even</lang> |
|||
=={{header|8051 Assembly}}== |
=={{header|8051 Assembly}}== |