如何在SMS32v50程序集中将BYTE寄存器的值分成两个半字节?

时间:2019-12-28 15:22:25

标签: assembly

我正在从键盘上获取ASCII值,例如按下键盘上的l,因此AL中的值为4Ch。我想将此值分成两个单独的值。

因此,在此示例中:4和C。
我正在使用sms32v50汇编代码。

1 个答案:

答案 0 :(得分:0)

Voilà:

    JMP Start       ; Skip past the data table

    DB "0123456789ABCDEF"   ; Hexadecimal characters

Start:

    CLO             ; Close unwanted windows.

Rep:
    IN  00          ; Wait for key press - Store it in AL.
    CMP AL,0D       ; Was it the Enter key? (ASCII 0D)
    JZ  E           ; Yes - end.

    PUSH AL         ; Save AL (restore it with POP)

    SHR AL          ; Isolate high nibble (four shifts)
    SHR AL
    SHR AL
    SHR AL

    ADD AL, 2       ; 02 is start address of data table
    MOV AL, [AL]    ; Copy data from table to AL
    MOV [C0], AL    ; Write character to VDU

    POP AL          ; Restore AL
    AND AL, 0F      ; Isolate low nibble

    ADD AL, 2       ; 02 is start address of data table
    MOV AL, [AL]    ; Copy data from table to AL
    MOV [C1], AL    ; Write character to VDU

    JMP Rep         ; Repeat the procedure

E:
    END