汇编语言:JE/JNE 作为 if-else

问题描述

所以我尝试使用 name: pulumi-preview-up on: [push] env: ARM_SUBSCRIPTION_ID: ${{ secrets.ARM_SUBSCRIPTION_ID }} ARM_CLIENT_ID: ${{ secrets.ARM_CLIENT_ID }} ARM_CLIENT_SECRET: ${{ secrets.ARM_CLIENT_SECRET }} ARM_TENANT_ID: ${{ secrets.ARM_TENANT_ID }} PULUMI_ACCESS_TOKEN: ${{ secrets.PULUMI_ACCESS_TOKEN }} jobs: preview-up-destroy: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: In order to use the Pulumi v2 action,we need to setup the Pulumi project specific language environment uses: actions/setup-node@v2 with: node-version: '14' - name: After setting up the Pulumi project specific language environment,we need to install the dependencies also run: npm install - name: Install Pulumi CLI uses: pulumi/action-install-pulumi-cli@v1.0.1 - uses: pulumi/actions@v2 with: command: preview stack-name: dev /JE 来执行 if-else 语句。问题是,它没有跳到我想要它去的地方。

我在这里要做的是使用 JNE 指令和仅 comparejump 命令将 2 个用户输入的数字相乘。

我正在考虑做一个 if-else 样式,但我无法继续,因为它无法跳转到其他标签。

这是我的代码:

ADD

所以如果 num1 == 1,那就没问题了。

但是当 num1 == 2 或更多时,它不会跳转到 equals2,而是继续。

这是示例输出:

.model small
.stack
.data
    str1 db "Enter first number: ","$" 
    
    str2 db 13,10,"Enter second number: ","$"
    
    str3 db 13,"The product of "
    num1 db ?," & "
    num2 db ?," is "
    prod db ?,"$" 
    
.code
    mov ax,@data
    mov ds,ax

    mov ah,9
    lea dx,str1
    int 21h
    
    mov ah,1
    int 21h ; takes user input for num1
    mov num1,al ; stores user input to variable input

    mov ah,str2
    int 21h
    
    mov ah,1
    int 21h ; takes user input for num2
    mov num2,al ; stores user input to variable input
    
    cmp num1,1 ; compare num1 to 1
    jne equals2 ; jump to equals2 if num1 != 1,otherwise,it will just continue
        mov al,num2
        mov prod,al
        
        mov ah,9
        lea dx,str3
        int 21h
        jmp endCode

equals2:        
        mov al,num2
        ADD al,al
        mov prod,al
        sub prod,49 ; convert hex to decimal
        
        mov ah,str3
        int 21h

endCode:
    mov ah,4ch
    int 21h

    mov ah,4ch
    int 21h
END

预期输出:

Enter first number: 2
Enter second number: 4
The product of 2 & 4 is 4

顺便说一句,用户输入必须是从 1 到 9。

解决方法

当按下 0 ... 9 键时,DOS.GetCharacter 函数 01h 将返回 48 ... 57(ASCII)范围内的值。

通常情况下,您只需减去 48 即可将这些 ASCII 代码转换为预期值。但是,此特定程序无需该步骤即可。
您可以直接与 ASCII 值进行比较。是引语将让一切变得不同!

    mov al,num2
    cmp num1,'1'   <<< See the quotes 
    je  printCode
    add al,al
    sub al,48      <<< Removing the duplicated bias
printcode:
    mov prod,al
    lea dx,str3
    mov ah,09h
    int 21h
endCode:

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...