【问题标题】:Why is this code never jumping to the label named true?为什么这段代码永远不会跳转到名为 true 的标签?
【发布时间】:2016-05-12 07:53:19
【问题描述】:

我一直试图弄清楚为什么我的代码不起作用。

我需要在此代码的更大版本中实现此 cmp 作为主菜单,要求选择继续执行某些操作,但是在比较 al, '1' 时无法识别 je 并直接跳转到 jne

我知道这可能是比较时的错误,但正确的方法是什么?

.model small

.stack 100h

.data

wm db 0ah, 0dh, "Welcome! please select one of the following options: $"

op1 db 0ah, 0dh, "Please submit 1 to true and 2 to false: $"

op1_1 db 0ah, 0dh, "its true!!! $"

op1_2 db 0ah, 0dh, "its false!!!! $"


.code

main PROC

    mov ax,@data

    mov ds, ax  
    mov dx, offset wm
    mov ah, 09h
    int 21h  

    mov dx, offset op1
    mov ah, 09h
    int 21h

    mov ah, 0ah
    int 21h

    cmp al, '1'
    je true
    jne false


success:

    mov ah,4ch                   ; function: DOS Exit Program
    mov al, 0                    ; specify return code 0
    int 21h                    ; adios amigo!

true:

    mov dx, offset op1_1
    mov ah, 09h
    int 21h
    jmp success

false:

    mov dx, offset op1_2
    mov ah, 09h
    int 21h
    jmp success

main ENDP

END main

【问题讨论】:

  • 请通过提出好问题来突出您的问题,而不是用符号标记它们。
  • 在问题中添加了粗体,以便您可以将问题与代码分开。我把代码作为我正在做的事情的参考,但是我首先指定了我想要完成的事情
  • 您应该将所有代码放在一个代码块中。我不知道 asm,所以不能确定我做得对。
  • 使用调试器单步执行您的代码。我猜你已经是了?大概al 不是'1',否则它将跳转到true,假设您的汇编程序以预期的方式处理ASCII 字符常量。 (如果不确定,请使用反汇编程序检查。)无论如何,使用调试器查看al
  • 'mov ah, 0ah' 你调用了错误的函数。你可能想要 int 21h/8 它在 AL 中返回按下的字符

标签: assembly x86 masm dos


【解决方案1】:

你没有传递足够的信息来运行0ah

mov ah, 0ah
int 21h

它需要缓冲区信息并将字符序列输入到用户提供的缓冲区中。我建议你使用

mov ah, 08h
int 21h

如您所料,它会在 al 中返回单个字符。它不会回显字符,但函数 01h 会。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-09
    • 2016-02-08
    • 2015-01-18
    • 1970-01-01
    • 2022-11-26
    • 1970-01-01
    相关资源
    最近更新 更多