Reputation: 10571
I am using the sms32v50 simulation tool.
I need to check the parity of a 16bit value (given in 2 registers). I should get the odd or even number of bits, returned as Signflag. This should be a procedure.
Upvotes: 0
Views: 3775
Reputation: 10571
Here is the complete working code, thanks a lot to harold! He has done nearly all of it!
-----------------------
MOV AL,03 ; register a, 1. part of input
MOV BL,03 ; register b, 2. part of input
; --------------
; For visual control, saving the inputs (temporary)
; --------------
PUSH AL
POP CL
PUSH BL
POP DL
; --------------
; Paritytest
; --------------
XOR AL, BL ; compare exclusive OR the both registers
PUSH AL ; A save temporary
POP BL ; A is taken back in B
SHL BL ; B is moved to the left, MSB get lost
SHL BL ; B is moved to the left, MSB get lost
SHL BL ; B is moved to the left, MSB get lost
SHL BL ; B is moved to the left, MSB get lost
XOR AL, BL ; compare exclusive OR the both regsiters
PUSH AL ; A temporary saved
POP BL ; A is taken in B
SHL BL ; B is moved to the left, MSB get lost
SHL BL ; B is moved to the left, MSB get lost
XOR AL, BL ; vergleiche exklusive ODER die beiden register
PUSH AL ; A zwischenspeichern
POP BL ; A wird in B zurueckgeholt
SHL BL ; B wird nach links geschoben, MSB geht absichtlich verloren
XOR AL, BL ; signflag is now set, if odd.
END
Upvotes: 0
Reputation: 64903
The sms32v50 asm language looks a lot like 8086 superficially, but is actually different in many areas. In this case, the most important difference is that it doesn't have a parity flag, so no shortcut.
So here's what it could look like (not tested)
XOR AL, BL ; assuming AL, BL are inputs
PUSH AL
POP BL
SHL BL
SHL BL
SHL BL
SHL BL
XOR AL, BL
PUSH AL
POP BL
SHL BL
SHL BL
XOR AL, BL
PUSH AL
POP BL
SHL BL
XOR AL, BL
; parity is now in sign flag (and the sign bit of AL)
Parity computation is just "xor all bits together". The idea here is that such a xor can be redistributed to make it more parallel. An other way, doing less in parallel, could look like this: (not tested)
XOR AL, BL
MOV CL, 8
_looptop:
PUSH AL
POP BL
SHL BL
XOR AL, BL
SUB CL, 1
JNZ _looptop
Or use a lookup table: (not tested)
JMP code
DB 0
DB -1
DB -1
DB 0
DB -1
DB 0
DB 0
DB -1
DB -1
DB 0
DB 0
DB -1
DB 0
DB -1
DB -1
DB 0
code:
XOR AL, BL
PUSH AL
POP BL
SHR BL
SHR BL
SHR BL
SHR BL
XOR AL, BL
AND AL, 15
ADD AL, 2 ; this 2 here assumes that the JMP to code is at 0,
; so you may need to add more to it
MOV AL, [AL]
OR AL, AL ; this is just to update the sign flag
Upvotes: 3