Click to See Complete Forum and Search --> : need help to display in MASM assembly
brad sue
March 23rd, 2009, 12:24 AM
Hi,
I have a display format issue in programming in assembly.
I want to enter a number via the keyboard and display a comment just after it, like this:
1001001 is not a palidrome
I have tried in vain to do it.
Here is my code and I would like to have some help on it:
.MODEL SMALL
.STACK 64
.data
inst db 100 dup(0)
mes1 db "Insert string:",0ah,0dh,'$'
mes2 db "It is a palindrome.$"
.code
.startup
mov ax,dx
mov es,ax
mov ah,09h
lea dx,mes1
int 21h
up: mov ah,01h
int 21h
cmp al,0dh
jz down
mov [inst+bx],al
inc bx
jmp up
down:
dec bx ; remove the return character
display:
mov ah,09h
lea dx, mes2
int 21h
jmp term
term: mov ah,4ch
int 21h
.exit
end
I tried to put ‘tab’ and ‘space’ character in front of the message, but it will erase the string I entered.
thank you
rxbagain
March 23rd, 2009, 12:59 AM
It behaves like that because int 21 func 01 echoes the input including the carriage return (0dh). To avoid this behavior, you can use function 8 (char input without echo) and echo it back (with function 2) only when it is not 0dh.
up: mov ah,08h
int 21h
cmp al,0dh
jz down
mov [inst+bx],al
inc bx
mov ah, 02h
mov dl, al
int 21h
jmp up
Hope it will help you
brad sue
March 31st, 2009, 11:53 PM
Thank you, it worked.
I also would like to limit the number of string entries to 100. What I did is test it with the reduce the number of 5.
like :
1100111
1110011
11111
111111
111111 "over the limit!"
This is what I did. I did not the whole code though. just the section I think is of interest.
The bolded section in "down " label is where I make made the check.
My logic was that it check the number of 'returns' it sees
The weird thing is that it works for cmp cx,1. but for 2 and above, it wont work .I don't know why. please can someone help me?
thank you
.MODEL SMALL
.STACK 64
.data
inst db 100 dup(0)
mes1 db 0ah,0dh, "Insert string:",0ah,0dh,'$'
mes2 db 20h,20h,"is a palindrome.$"
mes3 db 20h,20h,"is not a palindrome.$"
mes4 db 20h,20h,"INVALID ENTRY!Terminate program.$"
mes5 db 20h,20h, "Over 100 entries! Terminate program.$"
.code
start: mov ax,@data
mov ds,ax
mov ah,09h
lea dx,mes1
int 21h
mov bx,00h
mov cx,00h
up:
mov ah,08h
int 21h
cmp al,0dh
jz down
mov [inst+bx],al
inc bx
mov ah, 02h
mov dl, al
int 21h
cmp al,32h
jae invalid
jmp up
down:
inc cx
cmp cx,5
jz illegal
mov di,00h
dec bx
check:
;code here
fail:
;code here
displayok:
;code here
invalid:
;;code
illegal:
mov ah,09h
lea dx,mes5
int 21h
jmp term
term: mov ah,4ch
int 21h
end start
.exit
rxbagain
April 1st, 2009, 12:34 AM
There must be something in your code that changes the value of CX. Investigate those codes you omitted and see where the CX is changed. If you can't find anything in your code check the interrupts you are calling, some interrupt function might have changed the value of CX.
Another issue I want to point out is your input buffer (inst). It is allocated for only 100 bytes but you are counting line numbers. If any of the 100 lines has more than 1 character, your buffer will overflow overwriting your other variables. Make the size enough to hold your expected total characters or make additional condition so you wont exceed the buffer size.
brad sue
April 2nd, 2009, 01:42 AM
thank you to pointing me the problem!
It was CX that caused me the problem. The code works fine now.
codeguru.com
Copyright WebMediaBrands Inc., All Rights Reserved.