你好,我有一個問題,我需要從用戶那裡得到輸入,輸入是一個數字和一個數字後的數字,數字可以是雙字 (hello , i got a question that i need to get input from user, the input is a number and digit after digit ,the number can be a doubleWord)


問題描述

你好,我有一個問題,我需要從用戶那裡得到輸入,輸入是一個數字和一個數字後的數字,數字可以是雙字 (hello , i got a question that i need to get input from user, the input is a number and digit after digit ,the number can be a doubleWord)

我正在製作一個程序,我想在其中從用戶那裡逐位獲取一個 10 位數字
(4,294,967,296) 並存儲所有數字並在 EAX 中製作
其中一個數字.
例如:輸入 = 1 2 3 4,EAX = 1234
我嘗試使用 2 位數字開頭,但遇到了一些問題,我不知道如何
從這裡繼續。非常感謝您的幫助,在此先感謝!

.model small
.STACK 100h
.data  
num dd ?
ten DB 10

.code
.386
   start:
   MOV AX, @DATA
   MOV DS, AX
   MOV AH,1
   INT 21H
   SUB AL,30H
   MOV BH,AL
   MOV AH,1
   INT 21H
   SUB AL,30H
   MOV CH,AL

   MOV AL,BL
   MUL ten 
   ADD AL,CH 
   push eax
   call printNum
   MOV AX, 4c00h
   INT 21h
   END start

參考解法

方法 1:

MOV AL,BL
MUL ten 
ADD AL,CH 

The above would produce the value of your 2‑digit number if you would have used the correct register. You have stored the first digit in BH, but you're using BL here!

.386
push eax

You are in emu8086. Forget about using 32‑bit registers. If you want to work with 32‑bit numbers, you'll have to store them in a couple of 16‑bit registers. e.g. DX:AX where DX holds the Most Significand Word and AX holds the Least Significand Word.


To solve your task of building a 10 digit number up to 4GB‑1, next codez will be useful:

Multiplying the dword in DI:SI by 10

mov  ax, 10
mul  si         ; LSW * 10 ‑> DX:AX
mov  si, ax
xchg di, dx
mov  ax, 10
mul  dx         ; MSW * 10 ‑> DX:AX
jc   Overflow
add  di, ax
jc   Overflow

Adding the new digit AL=[0,9] to the dword in DI:SI

mov  ah, ah
add  si, ax
adc  di, 0
jc   Overflow

Looping until the user presses Enter

Input:
  mov  ah, 01h    ; DOS.GetKeyWithEcho
  int  21h        ; ‑> AL
  cmp  al, 13     ; Is it <ENTER> ?
  je   Done
  sub  al, '0'    ; From character to digit
  cmp  al, 9
  ja   Invalid

  ...

  jmp  Input
Done:

It's important that you decide how you will handle an invalid user input and what you will do for an input that yields a number bigger than 4GB‑1. Many programs have been written that overlook this and then at some point mysteriously fail...

(by daniel evanenkoSep Roland)

參考文件

  1. hello , i got a question that i need to get input from user, the input is a number and digit after digit ,the number can be a doubleWord (CC BY‑SA 2.5/3.0/4.0)

#emu8086 #assembly #x86-16 #x86 #dos






相關問題

使用 include 'emu8086.inc' 反轉字符串的大小寫和順序 (Reverse case and order of a String using include 'emu8086.inc')

emu8086 : ARR 不包含任何值 (emu8086 : ARR do not contain any value)

為什麼這個彙編代碼不刪除擴展名為“.lnk”的文件? (Why doesn't this assembly code delete the file with ".lnk" extension?)

將 C 代碼轉換為 8086 程序集 (Converting C code into 8086 assembly)

循環無法打印字母 (Loop does not work to print alphabets)

如何使用 call 和 ret 更改堆棧內容? (how to change stack content with call and ret?)

彙編語言中的putch函數通過堆棧 (putch function in assembly language through stack)

如何在不使用 HLT 的情況下對程序進行 HLT (How to HLT the program without using HLT)

使用 8086 彙編計算 10 的階乘 (Computing the factorial of 10 using 8086 assembly)

你好,我有一個問題,我需要從用戶那裡得到輸入,輸入是一個數字和一個數字後的數字,數字可以是雙字 (hello , i got a question that i need to get input from user, the input is a number and digit after digit ,the number can be a doubleWord)

在彙編語言中得到錯誤的結果 (Getting wrong result in Assembly language)

我的氣泡代碼是彙編語言嗎? (is my code for bubble right at assembly language?)







留言討論