Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Assembly Language Programming (ALP) Forum (http://www.go4expert.com/forums/assembly-language-programming-forum/)
-   -   im trying to modify this coding...help anyone (http://www.go4expert.com/forums/im-trying-modify-codinghelp-t6957/)

pengait 21Oct2007 21:05

im trying to modify this coding...help anyone
 
Code:

.model small
.386
.stack 200h
.data
msg1 db 13,10, "This is a program to perform logical operations $"
msg2 db 13,10, "on binary,  $"

msg4 db 13,10, "Enter first data(16bit ): $"
msg5 db 13,10, "Enter second data(16bit): $"
msg7 db 13,10, "Select operation: $"
msg8 db 13,10, "1-XOR 2-XNOR $"
msg9 db 13,10, "Invalid operand! Please reenter. $"
msg10 db 13,10, "Invalid operation! Please reenter. $"
msg11 db 13,10, "Answer: $"
msg12 db 13,10, "Enter y or Y to repeat the program. $"
msg13 db 13,10, "$"
opchoic db 2,3 dup(?)
bina1 db 17,18 dup(?)
data db 2,3 dup(?)

.code
start:
mov ax, seg msg1
mov ds, ax
mov dx, offset msg13
mov ah, 09h
int 21h
mov dx, offset msg1
int 21h
mov dx, offset msg2
int 21h

opchoice:                        ;choose operation
mov dx, offset msg7
mov ah, 09h
int 21h
mov dx, offset msg8
int 21h
mov dx, offset opchoic
mov ah, 0ah
int 21h
mov di, offset opchoic[2]
mov dh, 0
mov dl, [di]
cmp dx, 31h
je binain1
mov di, offset opchoic[2]
mov dh, 0
mov dl, [di]
cmp dx, 32h
je binain1



mov dx, offset msg10
mov ah, 09h
int 21h
jmp opchoice


binain1:                        ;first binary data input
mov bx, 0
mov dx, offset msg4
mov ah, 09h
int 21h
call binain
call binacheck
cmp bx, 1
je binain1
call binaconv



binain2:                        ;second binary data input
mov bx, 0
mov dx, offset msg5
mov ah, 09h
int 21h
call binain
call binacheck
cmp bx, 1
je binain2
call binaconv
jmp recheckopbi

recheckopbi:
mov di, offset opchoic+2
mov dh, 0
mov dl, [di]
cmp dx, 31h
je xorop
jmp xnorop


recheckophe:
mov di, offset opchoic+2
mov dh, 0
mov dl, [di]
cmp dx, 31h
je xorop


xorop:                                ;xor operation
pop bx
pop ax
xor ax, bx
push ax
jmp convbina

xnorop:
pop bx
pop ax
xor ax, bx
push ax
jmp notop

notop:
pop ax
not al
push ax
jmp convbina

convbina:                        ;convert hexadecimal to binary and display
mov cx, 16
pop ax
loopcbina1:
mov dx, 2
div dl
mov bh, 0
mov bl, ah
push bx
loop loopcbina1
mov dx, offset msg11
mov ah, 09h
int 21h
mov cx, 16
loopcbina2:
mov dx, 0
pop dx
add dx, 30h
mov ah, 06h
int 21h
loop loopcbina2
jmp finish


finish:
mov dx, offset msg12
mov ah, 09h
int 21h
mov dx, offset data
mov ah, 0ah
int 21h
mov di, offset data+2
mov dh, 0
mov dl, [di]
cmp dx, 59h
je start
cmp dx, 79h
je start
.exit

binain proc near                ;binary input procedure
mov dx, offset bina1
mov ah, 0ah
int 21h
ret
binain endp



binacheck proc near                ;binary validity checking procedure
mov cx, 16
mov di, offset bina1+2
binacheck1:
mov dh, 0
mov dl, [di]
inc di
cmp dx, 30h
je loopbina
cmp dx, 31h
je loopbina
mov bx, 1
mov dx, offset msg9
mov ah, 09h
int 21h
jmp donebck
loopbina:
loop binacheck1
donebck:
ret
binacheck endp



binaconv proc near                ;binary to hexadecimal conversion procedure
mov bx, 0
mov cx, 16
mov di, offset bina1+9
mov dx, 1
binaconv1:
push dx
mov dl, [di]
dec di
mov ax, dx
pop dx
sub al, 30h
mul dl
add bx, ax
mov ax, dx
mov dx, 2
mul dl
mov dx, ax
loop binaconv1
pop dx
push bx
push dx
ret
binaconv endp


end start

this is my program... xor and xnor program.
suppose the input are 8 bit..
i want to make this program where the input can be up to two bytes( that is 16 bit) and give correct answer..
i have try to modify it, but the result are not correct.
pls help me.
where should i change the coding and what should i do..
thanks for the help...

shabbir 21Oct2007 21:06

Re: im trying to modify this coding...help anyone
 
You should also try to explain what you have code for so that its easy for us to understand and suggest.

pengait 21Oct2007 21:38

Re: im trying to modify this coding...help anyone
 
sorry for that...
im using tasm.
this program will do a logical operations....that is XOR and XNOR operation..
the code i have display is the code for the whole program..

the problem is;
when i set the input in 8 bit, i can get correct answer.
but what i want is; the input = 16 bit...and get a correct 16 bit answer.

when i insert first input = 1111111111111111(16bit)
second input= 0000000000000000
answer = 1111111011111111

suppose my answer should be all '1'..

i think here is my main problem. that is, conversion hexadecimal to binary.
Code:

convbina:                        ;convert hexadecimal to binary and display
mov cx, 8
pop ax
loopcbina1:
mov dx, 2
div dl
mov bh, 0
mov bl, ah
push bx
loop loopcbina1
mov dx, offset msg11
mov ah, 09h
int 21h
mov cx, 8
loopcbina2:
mov dx, 0
pop dx
add dx, 30h
mov ah, 06h
int 21h
loop loopcbina2
jmp finish

hope my explanation help..
sorry my grammar is not that very good.

OrB-LeMoN 12Mar2008 08:51

Same here, I m also having the same problem...
 
I m asked to do write a code to perform logic operation for xor and xnor which can accept inputs up to 2 bytes(16 bits). Moreover, my program should be able to do the operation for hexadecimal and binary inputs. Can anyone pls help us out to complete to code as shown by pengait above?

Really need help... :(


All times are GMT +5.5. The time now is 05:13.