; *********************************************************************** ; * * ; * Compare Two Signed 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 signed integers as used in assembly language programs. ; ; Note the use of the signed-integer variant of the branch instruction: ; "bgt" is "branch if greater than", and implies the previous comparison ; instruction was with signed numbers. ; ; This program is essentially the equivalent of cmp-c-s.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) bgt exit ; Return a (a > b) [Signed 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