汇编语言中的 IF ELSE 和 ENDIF 指令是什么?我正在尝试制作一个程序,其中显示一些条件真实消息

发布于 2025-01-11 22:46:52 字数 327 浏览 3 评论 0原文

Dosseg
.model small
.stack 100h
.data

X db 89
z db ?

msg1 db "heloo
quot;


.code
main proc

mov ax,@data
mov ds,ax

mov z,offset x
;X=89
Y=-3
IF (z LT 0) OR (z GT 79)
lea dx,msg1
mov ah,9
int 21h
ENDIF

IF (Y LT 0)
lea dx,msg1
mov ah,9
int 21h
ENDIF 
   
mov ah,4ch
int 21h

MAIN ENDP
END MAIN
Dosseg
.model small
.stack 100h
.data

X db 89
z db ?

msg1 db "heloo
quot;


.code
main proc

mov ax,@data
mov ds,ax

mov z,offset x
;X=89
Y=-3
IF (z LT 0) OR (z GT 79)
lea dx,msg1
mov ah,9
int 21h
ENDIF

IF (Y LT 0)
lea dx,msg1
mov ah,9
int 21h
ENDIF 
   
mov ah,4ch
int 21h

MAIN ENDP
END MAIN

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

等数载,海棠开 2025-01-18 22:46:52

如问题所示, if else endif 是包含或排除汇编代码行的汇编时间条件。在 Microsoft Masm(6.11 或更高版本)中,.if .else .endif 是运行时条件。链接到 Masm 点指令:

https: //learn.microsoft.com/en-us/cpp/assembler/masm/directives-reference?view=msvc-170

As shown in the question, if else endif are assembly time conditionals that either include or exclude lines of assembly code. In Microsoft Masm (6.11 or later), .if .else .endif are run time conditionals. Link to Masm dot directives:

https://learn.microsoft.com/en-us/cpp/assembler/masm/directives-reference?view=msvc-170

另类 2025-01-18 22:46:52

在结构化编程中,我们有 if-then 语句,它的模式如下:

if ( condition ) 
    then-part

在汇编语言的 if-goto-label 风格(仍然是 C 语言)中,相同的模式如下:

    if ( ! condition ) goto endIf1;
    then-part
endIf1:

在 if-goto-label 风格中,我们告诉程序何时跳过 then 部分,与 C 相比,我们告诉程序何时执行 then 部分。因此,需要否定 if-goto-label 的条件。

构造 if ( condition ) goto endIf1; 是条件分支的 C 版本。在汇编语言中,条件分支通常作为比较和比较来完成。分支序列。例如:

if ( Y < 0 ) 
    print "hello"

变为:

    if ( Y >= 0 ) goto endIf1;
    print "hello"
endIf1:

变为:

    cmp Y, 0
    jge endIf1
    lea dx, msg1
    mov ah, 9
    int 21h
endIf1:

In structured programming we have the if-then statement, which has a pattern like this:

if ( condition ) 
    then-part

In assembly language's if-goto-label style (while still in C) the same pattern is like this:

    if ( ! condition ) goto endIf1;
    then-part
endIf1:

In the if-goto-label style, we tell the program when to skip the then-part, as compared with C where we tell the program when to execute the then-part.  Thus, the condition for if-goto-label needs to be negated.

The construct if ( condition ) goto endIf1; is C's version of a conditional branch.  In assembly language that conditional branch is usually done as a compare & branch sequence.  For example:

if ( Y < 0 ) 
    print "hello"

becomes:

    if ( Y >= 0 ) goto endIf1;
    print "hello"
endIf1:

which becomes:

    cmp Y, 0
    jge endIf1
    lea dx, msg1
    mov ah, 9
    int 21h
endIf1:
将军与妓 2025-01-18 22:46:52

以下是使用 ifdef 的适当时机的示例:

CPU_8086 equ 1 ;comment this line out to enable "shr al,4"

PrintHex:
   push ax
   ifdef CPU_8086
      shr al,1
      shr al,1
      shr al,1
      shr al,1
   else
      shr al,4  ;original 8086 couldn't do this
   endif

   call PrintHexChar
   pop ax
PrintHexChar:
   and al,0Fh
   daa
   add al,0F0h
   adc al,40h
   mov ah,0Eh
   int 10h
   ret

Here's an example of an appropriate time to use ifdef:

CPU_8086 equ 1 ;comment this line out to enable "shr al,4"

PrintHex:
   push ax
   ifdef CPU_8086
      shr al,1
      shr al,1
      shr al,1
      shr al,1
   else
      shr al,4  ;original 8086 couldn't do this
   endif

   call PrintHexChar
   pop ax
PrintHexChar:
   and al,0Fh
   daa
   add al,0F0h
   adc al,40h
   mov ah,0Eh
   int 10h
   ret
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文