assembly Easy68K使用循环将文本转换为大写

p3rjfoxz  于 2023-10-19  发布在  其他
关注(0)|答案(1)|浏览(122)

我坚持我的代码为M68000使用Easy68k模拟器。我得到一些文本,我把文本存储到注册表A0中,然后得到一个选项,把它转换为大写,并在A0中循环。
我不确定循环部分。我试图将字符转换为大写,但所有转换后的最终输出似乎是0。我卡住了,你能给我指个方向吗?

CR  EQU       $0D
LF  EQU       $0A

START: ORG    $1000
* load dialog WRITE in memory
    LEA WRITE,A1
    MOVE #0,D2 ;D2 stores transformed string

* show prompt WRITE
    MOVE #14,D0
    TRAP #15
* read input WRITE
    MOVE #2,D0 ;lee el input de la cadena
    TRAP #15
    MOVE A1,A0

*Show prompt CHOOSE
SR_CHOOSE:
    LEA CHOOSE,A1     
    MOVE #14,D0
    TRAP #15
    
* Read input CHOOSE
    MOVE #4,D0 ;read num input
    TRAP #15
    CMP.B #1,D1
    BEQ LOOP_UPPER
    BLE SR_CHOOSE

LOOP_UPPER:
    CMP.B   #0, (A0)  ; Compare byte at (A0) with zero (null terminator)
    BEQ     FINISHED
    SUB.B   #32, (A0) ; Convert to uppercase
    MOVE    A0, D2
    TST.B   (A0)+      ; Move to the next character and check for null terminator
    BNE     LOOP_UPPER

*Show transformed text*
FINISHED: 
    MOVE D2,A1  ;Set A1 to D2
    MOVE #14,D0
    TRAP #15

    SIMHALT

*Mensajes
WRITE: DC.W    'ESCRIBE ALGO: ',CR,LF,0
CHOOSE: DC.W    'Transforma a 1-MAYUSCULAS, 2-MINUSCULAS: ',CR,LF,0
        END     START

1.写文本,即你好
1.选择变换选项1(目前为大写)
1.循环通过文本并转换
1.预期:HELLO,实际:0

xlpyo6sf

xlpyo6sf1#

我的阅读:

LOOP_UPPER:
    CMP.B   #0, (A0)  ; Compare byte at (A0) with zero (null terminator)
    BEQ     FINISHED
    SUB.B   #32, (A0) ; Convert to uppercase
    MOVE    A0, D2
    TST.B   (A0)+      ; Move to the next character and check for null terminator
    BNE     LOOP_UPPER

D2将在每次循环迭代时加载新的A0值。因此,当循环退出时,D2将指向尾随的null终止符。
因此,当你在循环结束后将地址D2移回A1后从地址D2打印时,你将从终止符打印,而不是从字符串的开头打印。
也许你只是想把那个动作从循环中拿出来?所以:

MOVE    A0, D2  ; Keep the string's start address for later

LOOP_UPPER:
    CMP.B   #0, (A0)  ; Compare byte at (A0) with zero (null terminator)
    BEQ     FINISHED
    SUB.B   #32, (A0) ; Convert to uppercase
    TST.B   (A0)+      ; Move to the next character and check for null terminator
    BNE     LOOP_UPPER

顺便说一下,我认为你的TST.B/BNE对所实现的是,你的循环将在遇到NULL时终止,就像CMP.B一样,或者在遇到空格时终止,因为那是字符32。你可能不需要条件句:

LOOP_UPPER:
    CMP.B   #0, (A0)  ; Compare byte at (A0) with zero (null terminator)
    BEQ     FINISHED  ; Could also be BEQ.S as the destination is close.
    SUB.B   #32, (A0)+ ; Convert to uppercase
    BRA     LOOP_UPPER

相关问题