Решение проблемы переполнения деления в сборке
Привет
Я работаю над заданием, и я столкнулся с переполнением деления после ввода моего ввода. Ниже я прикрепил то, что я должен делать (в верхней части моего кода), и я прикрепил свой код.
; Number Conversion Program ; ; Requirement #1: Your program should clearly prompt the user with a message to enter an exactly 4 digit decimal number, which you should store as a nullterminated string (i.e., 5 characters total). Requirement #2: If the user types fewer than 4 digits before pressing return, then your program should ask for a 4 digit number again. Otherwise, your program should efficiently convert the 4 character numeric string into a 16-bit numeric value and store this in a word variable. Requirement #3: Using a loop, convert the 16-bit value into a 16 character string of ‘0’s and ‘1’s. Store this in another null-terminated string. org 100h section .text start: mov bx, input ;get address of first char for input mov cx, 2 myloop: mov ah, 00h ;service 00h (get keystroke) int 16h ;call interrupt 16h (AH=00H) and character read will now be in AL cmp al, 0Dh ;check if user pressed enter je convert ;if so, convert mov [bx], ax ;if not, store character inc bx ;point BX to next char of input jmp myloop ;repeat for next character convert: div cx ;dividing the number by 2 since binary is base 2 add dx, 30h cmp ax, 0 je output mov [bx], al inc bx jmp convert output: mov dl, [bx] ; get char at address in BX inc bx ; point BX to next char in message cmp dl, 0 ; Is DL = null (that is, 0)? je quit ; If yes, then quit mov ah, 06 ; If no, then call int 21h service 06h int 21h ; to print the character jmp myloop ; Repeat for the next character quit: int 20h ;quit program section .data input db 0, 0, 0, 0, 0
Jason Gleim
Переполнения почти всегда происходят из циклов в коде или при добавлении больших чисел и попытке поместить сумму в регистр, который слишком мал. Если вы запускаете приложение с небольшими числами, и оно все еще переполняется, это, вероятно, цикл. (подсказка... подсказка)
Поскольку это похоже на домашнее задание, хотя... не ожидайте, что кто-то скажет вам, где ошибка. Мы не делаем домашних заданий... так ты ничему не научишься.