; *********************************************************************** ; * * ; * Compare Two Unsigned Integer Numbers (Assembly Language Version) * ; * * ; *********************************************************************** ; Authors: Saeid Nooshabadi and John Zaitseff ; Date: 5th May, 2003 ; Version: 1.3 ; This very simple program compares two numbers together and returns the ; greater value. The whole point of this program is to illustrate the ; concept of unsigned integers as used in assembly language programs. ; ; Note the use of the unsigned-integer variant of the branch instruction: ; "bhi" is "branch if higher", and implies the previous comparison ; instruction was with unsigned numbers. ; This program is essentially the equivalent of cmp-c-u.c ; ----------------------------------------------------------------------- ; Assembly-language preamble for the main module .text ; Executable code follows _start: .global _start ; "_start" is required by the linker .global main ; "main" is our main program b main ; Start running the main program ; ----------------------------------------------------------------------- ; Start of the main program main: ldr r3, =a ; Load the address of a into R3 ldr r0, [r3] ; R0 = 0xE0001234 ldr r1, [r3, #4] ; R1 = 0x00004567 (NB: this assumes that ; R3 + 4 = address of b; in general, ; you should never make such assumptions! cmp r0, r1 ; Compare a and b (a - b) bhi exit ; Return a (a > b) [Unsigned branch] mov r0, r1 ; Return b (a =< b) exit: mov pc, lr ; Stop the program (and return to OS) ; R0 contains the exit code (return value) ; ----------------------------------------------------------------------- ; Program variables (stored together with the code) a: .word 0xE0001234 ; Variable "a" b: .word 0x00004567 ; Variable "b" ; ----------------------------------------------------------------------- .end