简体   繁体   English

组件8088打印AX,BX,AH,AL,BH,BL

[英]Assembly 8088 Print AX, BX, AH, AL, BH, BL

I am working on some stuff for a class of mine and I am stuck on an issue to keep me from progressing. 我正在为某类我的东西做一些工作,但为了避免我的进步,我一直陷在一个问题上。

In the code below on line 10, 14 and 16 I need to print out the respective values to what the comments state. 在下面的第10、14和16行的代码中,我需要将各个值打印为注释状态。 Currently I use the testPrint functions a bit lower to print out the values weather its for AX and BX or AH , AL , BH , BL . 当前,我使用较低的testPrint函数来打印AXBXAHALBHBL天气值。 My issue is when I try to print out vaules at line 10, and use the same function to print out values on line 14, the values on line 14 are messed up and show something that is not the correct answer. 我的问题是,当我尝试在第10行打印出有效值,并使用相同的函数在第14行打印出值时,第14行的值被弄乱了,并显示出不正确的答案。 When i let the program do all the proper functions like ADD , MUL etc. and print it out once at the end it works perfectly. 当我让程序执行所有适当的功能(例如ADDMUL等)并在最后将其打印一次时,它可以完美运行。

I can also only use one of the test print functions because the numbers get messed up if I try to use both at the same time. 我也只能使用其中一种测试打印功能,因为如果我尝试同时使用这两种功能,数字会变得一团糟。

I am using 8088 Assembler. 我正在使用8088汇编程序。

Am I missing something after calling each print function? 调用每个打印函数后我是否缺少某些东西? Could anyone show show me or tell me what I need to do to head in the right direction? 有人可以显示给我看或告诉我朝正确的方向前进需要做什么吗?

Thank You so much! 非常感谢!

This is the code:

_EXIT = 1       ! 1
_PRINTF = 127       ! 2
.SECT .TEXT         ! 3
    start:          ! 4 
MOV AX, 514         ! 5 AX = 514
MOV BX, 2       ! 6 BX = 2

firstOutput:        ! 7output original values of AX and BX
PUSH BX         ! 8
PUSH AX         ! 9
            ! 10 PRINT AX AND BX HERE (SHOULD BE 514,2)

secondOutput:           ! 11 BH = BH + BL; AH= AH - AL
ADDB BH, BL     ! 12
SUBB AH, AL     ! 13
            ! 14 PRINT AX AND BX HERE (SHOULD BE 2, 514)

thirdOutput:        ! 15 MULTIPLY AX AND BX
MUL BX          ! 16
            ! 17 PRINT AH, AL, BH, BL


!testPrint: !THIS WILL PRINT AX AND BX
!PUSH BX
!PUSH AX
!PUSH print
!PUSH _PRINTF
!SYS

testprintall: ! THIS WILL PRINT AH, AL, BH, BL
MOV CX, 0           ! 
MOVB CL, BL         ! 
PUSH CX             ! 
MOVB CL, BH         ! 
PUSH CX             ! 
MOVB CL, AL         ! 
PUSH CX             ! 
MOVB CL, AH         ! 
PUSH CX             ! 
PUSH printahalbhbl  ! 
PUSH _PRINTF        ! 
SYS !

exit:                   ! Exit 
PUSH 0              ! 
PUSH _EXIT          ! 
SYS                 !

 .SECT .DATA            ! 
 print:                 ! 
 .ASCIZ "AX:%d, BX:%d\n" !  
 .SECT .BSS                 ! 

 printahalbhbl:             ! 
 .ASCIZ "AH:%d, AL:%d, BH:%d, BL:%d\n" !
 .SECT .BSS                 !

Two things are missing here: 这里缺少两件事:

First is saving all registers that the _printf is allowed to change. 首先是保存所有允许_printf更改的寄存器。 AX is among them. AX就在其中。 Second is cleaning the stack after the call. 第二是在调用后清理堆栈。 Generally the called function doesn't know how many parameters the caller has put on the stack, so this is typically left as the responsibility of the caller. 通常,被调用函数不知道调用方已将多少参数放入堆栈,因此通常由调用方负责。

  push ax  ;; or even pusha
  push bx  ;; 

  push ax
  push bx
  call xxx
  pop  ax   ;; dummy pop to clean the stack
  pop  ax   ;; stack cleaning

  pop  bx   ;; restore BX
  pop  ax   ;; restore ax

Because each function is required to save bp , it's also possible to restore the stack after a call by 因为每个函数都需要保存bp ,所以在调用by之后还可以恢复堆栈

  push bp
  mov bp, sp

  push ax ; arguments
  push bx ;
  call xxx       ;; 

  mov sp, bp
  pop bp

or when this local stack frame concept is used throughout the system: 或在整个系统中使用此本地堆栈框架概念时:

  mov [bp - xyz ], sp;   // save current stack pointer at a fixed place
  push cx ; // push a lot of arguments
  call zyx
  mov sp, [bp - xyz]     // restore stack pointer

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM