Search code examples
assemblynasmdosx86-16integer-division

Display of modulus remainder


Good day,New to nasm here. This is run in win32(org 0x100). Want to display the modulus remainder next to mess4 "the remainder is:" after the input(1-9) was given and if 7 or 8 or 9 then give the remainder from modulus. Another problem is that still getting use to syntax so my "cmp" from input to 7(also 8 and 9 as 7 can divide into 8,9 and has remainder 1,2) catches on input values 1 and 2 as this is the same as remainder after dividing 8 and 9 with 7 has remainder 1 and 2 so gives a false reading. Any help would be appreciated. Thank you!

Tried changing and moving in registrars to no avail.

Update: i'm able to display remainder on screen, only issue is to get appropriate call when dividing 7 so that it only calls 'isdiv' when value 7,8,9 is given.

bits 16
org 0x100 ; start offset at memory position 100
jmp main ; jump to main program
;
; Data definitions
;
mess1: db 'Input any number (1 - 9)', 0dh,0ah,'$'
mess2: db 'The number is divisible by 7',0dh,0ah,'$'
mess3: db 'The number is not a divisible by 7',0dh,0ah,'$'
mess4: db 'The remainder is: ',0ah, 0dh,'$'                     ;Not sure
errmess: db '**',0dh,0ah,'$'
crlf: db 0dh,0ah, '$'
;
; Display a string on the screen
; DX contains the address of the string
;
display:
    mov ah,09 
    int 21h 
    ret
;
;Display the remainder
remainder:

    mov dx,mess4
    call display
    ret
; Set the cursor position
;
cursor:
    mov ah,02
    mov bh,0 ; screen number mov
    mov dh,05h ; row
    mov dl,0 ; column
    int 10h
    ret
;
; Display a user prompt
;
prompt:
    mov dx,mess1
    call display
    ret
;
; Read one character from the keyboard
;
input:
    mov ah,01
    int 21h
    ret
;
; Clear screen and change screen colour
;
screen:
    mov ah,06 ; scroll up screen
    mov al,0 ; lines to scroll where 0 clear entire screen
    mov cx,0 ; starting row:column
    mov dl,80 ; ending row;column
    mov dh,80
    mov bh,00011110b ; colour: yellow on blue
    int 10h
    ret
;
; Carriage returnm and line feed
;
newline:
    mov dx,crlf
    call display
    ret
;
; Main program
;
main:
    call screen
    call cursor

next:
    call prompt
    call input
    cmp al,'1' ; character < 1?
    jl error ; yes, error message
    cmp al,'9' ; character > 9?
    jg error ; yes, error message   
    sub al,30h ; convert from ASCII to numeric
    xor ah,ah ; clear AH
    mov bl,7    
    idiv bl ; divide by 7
    mov ch,ah
    ;cmp ah,0  ; remainder = n0?
    je isdiv ; yes: divisible by 7
    call newline
    mov dx,mess3 ; not divisible by 7
    call display
    jmp fin



isdiv:
    call newline
    mov dx,mess2
    call display ; divisible by 7
    call remainder
    add ch,30h
    mov dl,ch
    mov ah,2h
    int 21h

fin:
    ;
    int 20h ; terminate program
    ; Display error message. Number out of range
    ;

error:
    mov dx,errmess
    call display
    jmp next

Solution

  • added mov cl,al ;to copy initial input for later use at cmp cl,7 and use jge isdiv to display remainder. this solved my issue.