; written 22 Feb 2000 by Wayne Wolf
; contains second if implementation from example 2-4
; in Computers as Components, (c) 2000 Morgan Kaufman

	AREA |hand$$code|, CODE, READONLY
x1 DATA

main
; compute and test the condition
		ADR r4,a ; get address for a
		LDR r0,[r4] ; get value of a
		ADR r4,b ; get address for b
		LDR r1,[r4] ; get value of b
		CMP r0, r1 ; compare a < b
; notice we don’t need a branch here
; the true block follows---all instructions conditioned on LT
		MOVLT r0,#5 ; generate value for x
		ADRLT r4,x ; get address for x
		STRLT r0,[r4] ; store value of x
		ADRLT r4,c ; get address for c
		LDRLT r0,[r4] ; get value of c
		ADRLT r4,d ; get address for d
		LDRLT r1,[r4] ; get value of d
		ADDLT r0,r0,r1 ; compute a+b
		ADRLT r4,y ; get address for y
		STRLT r0,[r4] ; store value of y
; we also don’t need to branch around the false block
; the false block follows---all instructions conditioned on GE
		ADRGE r4,c ; get address for c
		LDRGE r0,[r4] ; get value of c
		ADRGE r4,d ; get address for d
		LDRGE r1,[r4] ; get value of d
		SUBGE r0,r0,r1 ; compute a-b
		ADRGE r4,x ; get address for x
		STRGE r0,[r4] ; store value of x
after		NOP ; code after the if statement

	AREA d1, DATA

dataseg

a
        DCD      0x00000000

b
        DCD      0x00000001

c
        DCD      0x00000002

d
        DCD      0x00000003

x
        DCD      0x00000004

y
        DCD      0x00000005

        EXPORT main
        EXPORT y
        EXPORT x
        EXPORT d
        EXPORT c
        EXPORT b
        EXPORT a

        END
