Skip to content

Instantly share code, notes, and snippets.

@a2902793
Last active December 23, 2020 15:40
Show Gist options
  • Save a2902793/f3c5e3c4a227b4d5b51707a5f14a5ecb to your computer and use it in GitHub Desktop.
Save a2902793/f3c5e3c4a227b4d5b51707a5f14a5ecb to your computer and use it in GitHub Desktop.
上課練習2
AREA PROG1, CODE ;This code is written by: 406500578 YENG, LI-CHUNG
ENTRY
;1. To put even parity for bits 6, 8, 10 of r0 into bit 1 of r1(with the other bits of r1 unchanged)
;2. To compare bit 10 of r1 with bit 9 of r0; if different, put 1 in r6; otherwise, put 0 in r6
LDR R0, =0xABCD
LDR r1, =0xBBFF
LDR r2, =0xBBAA
LDR r3, =0xFFDD
;---------------------------------------------------------------------
;Generate parity bit for bits 6, 8, 10
MOV r7, #0 ;init eor result placeholder
MOV r8, #6 ;init count=6
LOOP MOV r4, r0, LSR r8 ;shift r0 [r8] bits left
MOV r5, r4 ;copy r4 to r5
BIC r5, #1 ;clear r4 0bit
SUB r5, r4, r5 ;subtract to find if bit is 1 or 0
EOR r7, r7, r5 ;perform exclusive or to find out parity
ADD r8, #2 ;count+=2
CMP r8, #12
BNE LOOP
;---------------------------------------------------------------------
;Put generated parity bit to bit 1 of r1(with the other bits of r1 unchanged)
BIC r1, #2 ;clear bit 1 of r1
ADD r1, r7, LSL #1 ;add generated parity bit to r1
LSL r1, #21 ;isolate bit 10 of r1
LSR r1, #31 ;(31-21=10)
LSL r0, #22 ;isolate bit 9 of r0
LSR r0, #31 ;(31-22=9)
CMP r1, r0 ;compare r1 and r0
MOVNE r6, #1 ;if different, put 1 in r6
MOVEQ r6, #0 ;otherwise, put 0 in r6
stop B stop
END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment