nasm - 16 bit Assembly Program -
so i've started learning 16 bit assembly using nasm on windows machine. if got little program i've created asks user input , determines if input within range (0 9). if is, goes on see if value divisible three, if not it's supposed loop , ask user value. here's code:
org 0x100 bits 16 ;jump on data declarations jmp main input: db 6 db 0 user: times 6 db ' ' cr_lf: db 0dh, 0ah, '$' message: db 'please enter number select between 0 , 9:','$' errormsg: db '***', 0ah, 0dh, '$' finalmsg: db 'number divisible 3!', 0ah, 0dh, '$' finalerrormsg: db 'number not divisible 3!', 0ah, 0dh, '$' outputbuffer: db ' ', '$' ;clear screen , change colours clear_screen: mov ax, 0600h mov bh, 17h ;white on blue mov cx, 00 mov dx, 184fh int 10h nop ret move_cursor: mov ah, 02 mov bh, 00 mov dx, 0a00h int 10h ret ;get user input get_chars: mov ah, 01 int 21h ret ;display string display_string: mov ah, 09 int 21h ret errstar: mov dx, errormsg call display_string int 21h jmp loop1 nextphase: cmp al, 30h ;compare input '0' i.e. 30h jl errstar ;if input less 0, display error message ;else call thirdphase ;input within range thirdphase: xor dx, dx ;set dx 0 divide operation ;at point al has value inputted user mov bl, 3 ;give bl value div bl ;divide al bl, remainder stored in dx, whole stored in ax cmp dx, 0 ;compare remainder 0 jg notequal ;jump not divisible 3 remainder greater 0 je end notequal: mov dx, finalerrormsg call display_string int 20h end: mov dx, finalmsg call display_string int 20h ;main section main: call clear_screen ;clear screen call move_cursor ;set cursor loop1: mov dx, message ;mov display prompt dx call display_string ;display message call get_chars ;read in character ;at point character value inputted user cmp al, 39h ;compare '9' i.e. 39h jle nextphase ;if value less or equal 9, move onto next phase jg errstar ;else call error , loop
anyway, value range checking works fine , looping works fine too. problem i've got @ divisible in 3 thirdphase section. understanding firstly need make sure dx contains value of 0. move value 3 bl. al contains user input, bl contains value 3, , dx 0. during div bl part, al divided bl value of 3. remainder stored in dx , if compared 0 , found greater should jump notequal section else jump end section.
as now, finalmsg displayed, supposed displayed if value divisible 3.
anyone have suggestions. thanks. jp.
you doing div bl
, dividing byte. quotient in al
, remainder in ah
, not in ax
, dx
, respectively, code assumes. make sure clear ah
before div
since dividend single byte in al
.
Comments
Post a Comment