在Tasm汇编程序MS-Dos中使用推入和弹出 [英] Using Push and Pop in Tasm Assembler MS-Dos

查看:79
本文介绍了在Tasm汇编程序MS-Dos中使用推入和弹出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


您能否让我知道以下程序中使用PUSH和Pop指令的含义.
1.为什么在Getc和Putc函数中必不可少的
2.在功能Getc中,为什么未编码Push AX和Pop AX,而
在Putc中编码相同的代码

任何帮助将不胜感激.

以下是供您参考的代码.

Hi,
Could you please let me know the meaning of using PUSH and Pop instructions in the following program.
1. Why are they necessarily required in functions Getc and Putc
2. In function Getc why Push AX and Pop AX is not coded and while the
same is coded in Putc

Any help would be appreciated.

Below is the code for your reference.

; program to get a character from a keyboard and then print to the screen
; Assembler: Tasm
; Operating system: MS-DOS 6.2
; compilation: Tasm test.asm
; linking:     tlink test.obj
; execution:   test.exe

.Model Small
.Stack 100H
.Code
   Start:
      Call Getc
      Call Putc
      Call Exit


      Getc:     ; gets a character from user
         ; this routine gets a character into the AX register
         Push BX
         Push CX
         Push DX
         Mov AH, 01H
         Int 21H
         Pop  DX
         Pop  CX
         Pop  BX
         Ret

      Putc:     ; prints a character to the screen
         Push AX
         Push BX
         Push CX
         Push DX
         Mov  DL, AL
         Mov  AH, 02H
         Int 21H
         Pop  DX
         Pop  CX
         Pop  BX
         Pop  AX
         Ret

      Exit:
         Mov AH, 4CH
         Int 21H
   End Start

推荐答案

PUSH将寄存器保存到堆栈中,而POP则将其恢复.

您显示的例程会保存外部寄存器,因为它们需要出于自身目的使用它们,并且不想破坏调用程序的寄存器.如果他们不这样做,那么调用程序将不得不在每次调用之前和之后进行操作,这既效率低下又很危险-如果您忘记了该调用的一个实例,则会得到损坏的寄存器,并且您的程序将无法运行.

例程以这种方式保存其工作寄存器是很正常的.

[edit]我丢了一封信! -OriginalGriff [/edit]
PUSH saves a register to the stack, POP restores it.

The routines you show save the external registers because they need to use them for their own purposes, and do not want to corrupt the registers for the calling program. If they didn''t do it, then the calling program would have to do it before and after each call, which is both inefficient, and dangerous - if you forget for just one instance of the call, you will get corrupted registers, and your program will not work.

It is pretty normal for a routine to save it''s working registers in this way.

[edit]I lost a letter! - OriginalGriff[/edit]


这篇关于在Tasm汇编程序MS-Dos中使用推入和弹出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆