Code 01:
AREA HALF, CODE
ENTRY
MOV R0, #3
MOV R9, #2
MOV R10, #0
OUT1 LDR R5, = 0X40000000
ADD R6, R5, #1
MOV R3, #2
IN1 LDRB R1, [R5]
LDRB R2, [R6]
CMP R1, R2
BCC LOP
MOV R4, R2
MOV R2, R1
MOV R1, R4
LOP STRB R1, [R5]
STRB R2, [R6]
ADD R5, R5, #1
ADD R6, R6, #1
SUBS R3, R3, #1
BNE IN1
SUBS R0, R0, #1
BNE OUT1
BEQ OUT2
OUT2 LDR R5,= 0X40000003
ADD R6, R5, #1
MOV R12, #1
IN2 LDR BR1, [R5]
LDR BR2, [R6]
CMP R1, R2
BCS LOP2
MOV R4, R2
MOV R2, R1
MOV R1, R4
LOP2 STRB R1, [R5]
STRB R2, [R6]
ADD R5, R5, #1
ADD R6, R6, #1
SUBS R12, R12, #1
BNE IN2
SUBS R9, R9, #1
BNE OUT2
STOP B STOP
END
Code 02:
AREA A0, CODE
ENTRY
MOV R6, #5
MOV R0, #0
MOV R1, #6
MOV R5, #0
LDR R7, = 0X40000000
LDR R8, = 0X40000018
LDR R11,= 0X4000002C
LOOP1 SUB R0, R1, #1
MOV R2, R7
MOV R4, R5
LOOP
LDR R3, [R2,#4]!
CMP R4, R3
MOVCC R4, R3
MOVCC R10, R2
SUBS R0, R0, #1
BNE LOOP
CMP R6, #3
BMI JUMP
SUBS R6, R6, #1
STR R4, [R8], #4
B JUMP1
JUMP
SUBS R6, R6, #1
STR R4, [R11,#-4]!
JUMP1
STR R5, [R10]
BNE LOOP1
STOP B STOP
END