首页 > 解决方案 > 如何在 SMS32v50 汇编中将 BYTE 寄存器的值拆分为两个半字节?

问题描述

我从键盘得到一个 ASCII 值,例如在l键盘上按下,所以 AL 中的值将是 4Ch。我想将此值拆分为两个单独的值。

所以,在这个例子中:4 和 C。
我使用的是 sms32v50 汇编代码。

标签: assembly

解决方案


瞧:

    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

推荐阅读