emu8086 - Why does the following 8086 assembly code can only display numbers upto 2559? -


what trying ?

i want 16bit number user , print on console.

what problem ?

well code works fine til number entered less 2600 movement enter 2600 displays "40" , 2601 "41" , on. shouldn't display numbers upto 65535 ? because storing value in bx register 16bit , stores @ 65535. why 2559 ?

my code:

.model small .data  msg db 10,13,'enter 16bit number: $'              newline db 10,13,'$'  .code main:  mov ax, @data mov ds, ax  mov cl, 10 mov bx, 0  mov ah, 09h lea dx, msg int 21h  call get16bitnum  mov ah, 09h lea dx, newline int 21h  mov ax, '$'  push ax  mov ax, bx        store:    div cl cmp al, 0  mov bh, 0 mov bl, ah     push bx je continue         mov ah, 0 jmp store  continue:  pop ax cmp ax, '$' je ext  mov bx, ax mov ah, 02h mov dx, bx add dx, 48 int 21h   jmp continue  ext:          mov ah, 04ch int 21h  proc get16bitnum  aggregate:  mov ah, 01h  int 21h  cmp al, 13 je return   mov ah, 0 sub al, 48       mov dx, bx mov bx, ax mov ax, dx  mul cl add bx,ax          jmp aggregate                          return:  ret      endp                  end main 

you don't retrieve 16-bit number!

you keep desired input in bx, , need multiply whole of bx 10. using word sized multiplication.

proc get16bitnum   aggregate:     mov  ah, 01h      int  21h     cmp  al, 13     je   return      mov  ah, 0     sub  al, 48    ;ax 0 9     xchg ax, bx    ;new digit temporarily in bx     mov  cx, 10     mul  cx        ;product in dx:ax, won't use dx!     add  bx ,ax    ;add new digit     jmp  aggregate                          return:     ret 

you don't display 16-bit number

the procedure convert number text need use word sized division.

for excellent explanation on how see recent post displaying numbers dos. explains in great detail need know converting numbers. uses same technique of pushing value in stack (you used $ character this) know number ends.

ps. if find info in the linked post useful don't hesitate upvote it. (of course hope find answer useful too!)


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -