0

我正在使用sms32v50 模拟工具

我需要检查 16 位值的奇偶校验(在 2 个寄存器中给出)。我应该得到奇数或偶数位,以 Signflag 形式返回。这应该是一个程序。

4

2 回答 2

3

sms32v50 asm语言表面上看起来很像8086,但实际上在很多方面都不同。在这种情况下,最重要的区别是它没有奇偶校验标志,因此没有捷径。

所以这就是它的样子(未经测试)

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)

奇偶校验计算只是“将所有位相异或”。这里的想法是可以重新分配这样的 xor 以使其更加并行。另一种方式,并行执行较少,可能如下所示:(未测试)

XOR AL, BL
MOV CL, 8
_looptop:
PUSH AL
POP BL
SHL BL
XOR AL, BL
SUB CL, 1
JNZ _looptop

或者使用查找表:(未测试)

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
于 2013-04-24T13:39:38.060 回答
0

这是完整的工作代码,非常感谢哈罗德!他几乎完成了所有这一切!

-----------------------

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
于 2013-04-30T07:16:32.740 回答