Hi,I'm new to assembly language and have been struggling to finish an assignment for days.Im using Nasm assembly language on a Windows 7 pc.I have done all of the coding but getting the incorrect output.The program must ask the user to input a number between 1 and 9,read every byte in the bit pattern array and the display the enlarged number on the screen,using the dollar character.The exact problem is the first byte in the array does not display as output,but the other bytes,diplays perfectly.So either my array indexing is incorrect or im using some register incorretly.In my code below im trying to display the number 5, hence use must enter 5 as input.
bits 16
org 0x100
jmp main
message: db 'Please enter a number between 1 and 9',0ah,0dh,'$'
arrnum5 db 1Fh,10h,1Ch,02h,01h,02h,1Ch ; enlarged 5
cr_lf: db 0ah,0dh,'$' ;move cursor to beginning of next line
;Display string
Display: mov ah,09h
int 21h
ret
;Display character
Display2: mov ah,02h
int 21h
ret
;Input character
Input: mov ah,07h
int 21h
ret
Print_num:
mov cl,8 ; cl counts the number of bits in the byte that has been read
Print:
cmp cl,0 ;if cl=0,then every bit in this byte has been read,
je Next ;then jump to Next to get next byte
rcl si,1 ;rotate the byte that si points to, left by 1 bit and check if
;the carry flag contians a 1 or zero.
jnc printSpace ;if carry flag contains a zero,jump to printSpace
printDollar: ;if carry flag contains a 1,print dollar sign
mov dx,'$' ;move dollar character into dx and print character
call Display2
dec cl ;decrement cl and jump to Print
jmp Print
printSpace: ;if carry flag contains a zero,print space character
mov dx,' ' ;move space character into dx and print character
call Display2
dec cl ;decrement cl and jump to Print
jmp Print
Next: ;move to next byte in the array
mov dx,cr_lf ;move cursor to beginning of next line
call Display
inc bx ;increment bx to calculate the index of next byte in the array
mov si,[arrnum5+(bx*1)] ;calculating index of next byte and store in si
inc ch ;increment ch to track the number of bytes in the array
cmp ch,6
jle Print_num ;while ch is less or equal than the array size,jump to Print_num
; to read next byte in array
ret
main:
Output:
mov dx,message ;move message into dx register
call Display ;display message to ask user input
call Input ;save the user input in the al register
mov dl,al ;move the input to the dl 8 bit register
push dx ;move dx register to stack,which contains the user input
;next line
mov dx,cr_lf ;dx register is empty,hence move cr_lf into
call Display ; register to display blank line
pop dx ;pop user input from stack back into dx register
sub dl,30h ;convert user input character to integer
line_loop:
cmp dl,5 ;check if user input is 5 than jump to printno
je printno
jmp Output ;if user input is not 5,than ask for user input again
printno:
mov bx,0 ;set bx to zero,to calculate the next index in array
mov ch,0 ;set ch to 0 to count bytes in array
mov si,0 ;initialize si to zero
mov si,[arrnum5] ;si points to the first index in the array...arrnum5[0]
call Print_num ;call function Print_num
jmp Done
Done:
int 20h