本文介绍了想要将变量中的值保存到寄存器中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用MASM编译器和DOSBOX.我想将变量中的值保存到寄存器中.我想将num1值保存到cx寄存器中.我该怎么办?

I m using MASM compilor and DOSBOX. I want to Want to save value from a variable into register. i want to save num1 value into cx register. How can i do that?

      .MODEL SMALL
.STACK  50H
.DATA
num1 db '5'
    NL  DB  0DH, 0AH, '$'        
    msg     db ?,0AH,0DH,"Enter an odd number between 0 to 10:$"
     nxtline db 0Ah,0DH,"$"
.CODE
MAIN PROC
    MOV AX, @DATA
    MOV DS, AX



              LEA DX,msg     
              mov ah,9
              int 21H
              LEA DX,nxtline    
              mov ah,9
              int 21H

              MOV AH,1                    
              INT 21H 
              LEA DX,nxtline    
              mov ah,9
              int 21H



       mov bl,al   ;save the value from input
              mov num1,bl
               LEA DX,num1     
              mov ah,9
              int 21H
              mov cl,al 

   main endp
   end main

推荐答案

您正在丢失用户在AL中输入的值.您可以这样输入一个字符:

You are losing the value entered by the user in AL. You input one char with this:

          MOV AH,1                    
          INT 21H 

字符存储在AL中,但是在将值保存到BL中之前,显示换行符:

The char is stored in AL, but before you save the value in BL you display a line break:

          LEA DX,nxtline    
          mov ah,9
          int 21H

AL中的值不见了,因为此中断使用AL显示字符串.解决方案是将值保存在BL 之前,显示换行符:

And the value in AL is gone because this interrupt uses AL to display a string. The solution is to save the value in BL before you display the line break:

          MOV AH,1                    
          INT 21H 
   mov bl,al   ;save the value from input
          LEA DX,nxtline    
          mov ah,9
          int 21H

将值移动到CX:

xor cx,cx       ;CLEAR CX.
mov cl,bl       ;MOVE CHAR INTO CL.
sub cl, 48      ;CONVERT CHAR TO DIGIT, EXAMPLE: '5' -> 5.

这篇关于想要将变量中的值保存到寄存器中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 16:12