Click here to Skip to main content

x.aerodynamik asked:

Open original thread
Hello
 
I am working on an assignment, and I`ve been encountering divide overflow after entering my input. Below, I`ve attached what I am supposed to do (on the top of my code), and I`ve attached my code.
 
; 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
Tags: programming

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the The Code Project Open License (CPOL).



Advertise | Privacy | Mobile
Web01 | 2.8.140709.1 | Last Updated 26 Mar 2009
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid