【问题标题】:if else statement (it only works with a number)if else 语句(它只适用于数字)
【发布时间】:2015-03-26 20:35:05
【问题描述】:

我可以在 mov ax 中放一个数字(例如:mov ax, 2),但是如果我放一个变量它就不起作用(例如:mov ax, forma)

我是组装新手。

这是代码:

    ;if eles 
    mov ax, 2 ;forma
    cmp ax , 2
    jge l8

    mov ah, 40h
    mov bx, 1
    mov cx, 2
    mov dx, pergunta3
    int 21h
    jmp l5


    l8:

    mov ah, 40h
    mov bx, 1
    mov cx, 3
    mov dx, pergunta2
    int 21h
    jmp l5

    l5:
    ;terminar
    mov ah, 4ch
    int 21h       

【问题讨论】:

  • 汇编中没有“变量”。充其量你已经命名了内存位置。
  • 请说明您正在使用的汇编程序,因为它们的语法不同,以及“它不起作用” 的含义。
  • 在数据段中声明格式:“forma dw 999”。现在你可以使用它了:“mov ax, forma”。
  • 对我来说看起来像 Nasm 语法。试试mov ax, [forma]。如果没有方括号,您将在 Masm/Tasm 中获得类似 mov ax, offset forma 的地址。
  • im 使用 fasm) 并且用户在格式中输入一个值,如果 (forma>2) 程序执行 (l8:)

标签: assembly


【解决方案1】:
;if eles 
mov ax, 2 ;forma
cmp ax , 2
jge l8

FASM 使用方括号 [ ] 来访问内存,例如您的变量 forma。所以像这样编码

mov ax,[forma]
cmp ax,2
jg l8

一种更短的编码方式是

cmp word [forma],2
jg l8

请注意您的评论说 (forma>2),因此 jge l8 应更改为 jg l8

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-08
    • 2021-08-26
    相关资源
    最近更新 更多