I was trying to learn ASM language using 30386 Micro porcessor and intend to write a program using it. I was trying t create a program that can add,sub,multiply and divide two decimal numbers in range between - 99.99 till +99.99 . I am hoping that any expertise out there can give a solution for my problem. right now i am still looking for the source code.
Regards,
isare
Comments
:
: Regards,
: isare
:
This may sound noobish, but are you sure you mean 30386, and not 80386?
If the 30386 is similar to 80386 it should be easy. By decimal numbers do you mean BCD (binary coded decimals)?
Why are you looking for the source code? Why not write it yourself?
:
You should try to be a bit more specific - what is it, that you are really having trouble with? Is it the arithmetic instructions? Making an interface? Converting between strings and integers, etc..? Try to make a plan on a piece of paper and then try to put the pieces together..
In case you don`t know the basics of 386 asm coding, you really ought to work on that before taking on a project.
We don`t really like to write complete programs for people..
:
All right, Ill try to give some info, step by step:
[b]1) Getting user input[/b]
For this you need to use the DOS interrupt 21h, function 0Ah.
You can find a nice example of it on this page in the "Input and Output to Screen" section:
http://www.geocities.com/SiliconValley/Park/3230/x86asm/asml1008.html
[b]2) Converting the user input string to a number[/b]
This can be tricky, here is one solution:
http://coding.derkeiler.com/Archive/Assembler/comp.lang.asm.x86/2004-01/0448.html
[b]3) Doing arithmetics[/b]
After converting the user input to binary numbers, you can directly perform arithmetic instructions on them. Depending on the selected operation, you can use the [green]add, sub, mul or div[/green] instructions, for example:[code]mov ax, Input1
sub ax, Input2[/code]
[b]4) Converting the resulting integer back to a string[/b]
This is also a tricky part, it might be hard to understand this kind of a function right away, but until then you can use some other code from the net.
A fairly good example of this is here (almost at the end of the page):
http://www.koders.com/assembler/fid590F0175D04B2E1078367FCD2FB631E89F866A25.aspx
[b]5) Displaying the output on the screen[/b]
This is also described in the "Input and Output to Screen" page.
I would recommend, that you use the FASM assembler, as it is the simplest for beginners: http://flatassembler.net
Good luck! Looking forward to hearing from any progess..
:
[blue]So, if you divide 10 by 3 - what result you expect from your calculator? When working with integers the result is 3, not 3.3333333333...[/blue]
Hello,
I have wrote a the codes. but there some that i havent start yet such as division. This are my problem :
1. multiplication didnt display correctly, if the answer is 1234.00 it will only display 34.00 -> hope that some one can correct it
2. division is still not started yet -> hope that someone can help me out
3. if you want to key in the input, you have to follow the format +02.34 and -12.34. everything must be include. -> can someone make it 2.34(without 0 )and if the input is positive, the + can can be discard.
4. help me with the division -> thanks alot
this are the codes :
.model small
.stack 200h
.386
.data
message1 db 10,13,"**************enter an option please:*********** $"
message2 db 10,13," 1.)Addition $"
message3 db 10,13," 2.)Subtraction $"
message4 db 10,13," 3.)Multiplication $"
message5 db 10,13," 4.)Division $"
message6 db 10,13,"Enter the number please $"
message7 db 10,13,"Number 1: $"
message8 db 10,13,"Number 2: $"
message9 db 10,13,"Answer =$"
message10 db 10,13,"thank you for using this oldschool calculator$"
message11 db 10,13,"False number,please enter the sign of the number with the floating point.$"
num1 db 32,33 dup(0)
num2 db 32,33 dup(0)
no1 dw ?
no2 dw ?
ans db 32,33 dup(0)
store1 db 32,33 dup(0)
store2 db 32,33 dup(0)
store3 db 32,33 dup(0)
store4 db 32,33 dup(0)
store5 db 32,33 dup(0)
opt db 32,33 dup(0);10
.code
start:
mov ax,seg message1
mov ds,ax
mov dx,offset message2
mov ah,09h
int 21h
mov dx,offset message3
mov ah,09h
int 21h;20
mov dx,offset message4
mov ah,09h
int 21h
mov dx,offset message5
mov ah,09h
int 21h
mov dx,offset message1
mov ah,09h
int 21h
mov dx,offset opt;30
mov ah,0ah
int 21h
mov dx,offset message6
mov ah,09h
int 21h
check1:
mov di,offset opt
mov ah,0
mov al,[di+2]
cmp al,'1'
je one
cmp al,'2'
je two
cmp al,'3'
je three
cmp al,'4'
je four
JNE FIVE
one:
mov dx,offset message2
mov ah,09h
int 21h
call getnum
call adjustsignedforadd
startaddition:
mov ah,0
mov di,offset num1
mov al,[di+3]
mov di,offset num2
mov bl,[di+3]
add al,bl
AAA
push ax
mov ah,0
mov di,offset num1
mov al,[di+4]
mov di,offset num2
mov bl,[di+4]
add al,bl
AAA
push ax
mov ah,0
mov di,offset num1
mov al,[di+6]
mov di,offset num2
mov bl,[di+6]
add al,bl
AAA
push ax
mov ah,0
mov di,offset num1
mov al,[di+7]
mov di,offset num2
mov bl,[di+7]
add al,bl
AAA
push ax
pop ax
add ax,3030h
mov di,offset ans
mov bl,ah
mov [di+7],al
pop ax
add ax,3030h
add al,bl;add carry
AAA
add al,30h
mov [di+6],al
mov bh,0
mov byte ptr [di+5],"."
mov bl,ah
pop ax
add ax,3030h
add al,bl
AAA
add al,30h
mov [di+4],al
mov bl,ah
pop ax
add ax,3030h
add al,bl
AAA
add al,30h
mov [di+3],al
call displayans
jmp last1
two:
mov dx,offset message3
mov ah,09h
int 21h
call getnum
call adjustsigned
startsubtract:
mov di,offset num1
mov ah,0
mov al,[di+7]
sub al,30h
mov di,offset num2
mov bh,0
mov bl,[di+7]
sub bl,30h
sub al,bl
AAS
add al,30h
mov di,offset ans
mov [di+7],al
cmp ah,0ffh
je adjustsub1
jne nonadjustedsub1
nonadjustedsub1:
mov di,offset num1
mov ah,0
mov al,[di+6]
sub al,30h
mov di,offset num2
mov bl,[di+6]
mov bh,0
sub bl,30h
sub al,bl
AAS
add al,30h
mov di,offset ans
mov [di+6],al
cmp ah,0ffh
je adjustsub2
jne nonadjustedsub2
jmp answer
nonadjustedsub2:
mov di,offset num1
mov ah,0
mov al,[di+4]
sub al,30h
mov di,offset num2
mov bh,0
mov bl,[di+4]
sub bl,30h
sub al,bl
AAS
add al,30h
mov di,offset ans
mov [di+4],al
mov byte ptr [di+5],"."
cmp ah,0ffh
je adjustsub3
jne nonadjustedsub3
jmp answer
nonadjustedsub3:
mov di,offset num1
mov ah,0
mov al,[di+3]
sub al,30h
mov di,offset num2
mov bh,0
mov bl,[di+3]
sub bl,30h
sub al,bl
AAS
add al,30h
mov di,offset ans
mov [di+3],al
jmp answer
adjustsub1:
mov di,offset num1
mov ah,0
mov al,[di+6]
sub al,30h
sub al,1;carry
mov di,offset num2
mov bh,0
mov bl,[di+6]
sub bl,30h
sub al,bl
AAS
add al,30h
mov di,offset ans
mov [di+6],al
cmp ah,0ffh
je adjustsub2
jne nonadjustedsub2
jmp answer
adjustsub2:
mov di,offset num1
mov ah,0
mov al,[di+4]
sub al,30h
sub al,1;carry
mov di,offset num2
mov bh,0
mov bl,[di+4]
sub bl,30h
sub al,bl
AAS
add al,30h
mov di,offset ans
mov [di+4],al
mov byte ptr [di+5],"."
cmp ah,0ffh
je adjustsub3
jne nonadjustedsub3
jmp answer
adjustsub3:
mov di,offset num1
mov ah,0
mov al,[di+3]
sub al,30h
sub al,1;carry
mov di,offset num2
mov bh,0
mov bl,[di+3]
sub bl,30h
sub al,bl
AAS
add al,30h
mov di,offset ans
mov [di+3],al
jmp answer
answer:
call displayans
jmp last1
three:
mov dx,offset message4
mov ah,09h
int 21h
call getnum
mov di,offset num1
mov al,[di+7]
sub ax,3030h
mov di,offset num2
mov bl,[di+7]
sub bx,3030h
mul bl
AAM
mov di,offset store2
mov [di+9],al;store 1st answer
mov di,offset store1
mov [di+2],ah
mov [di+1],al
mov di,offset num1
mov al,[di+6]
sub al,30h
mul bl
AAM
mov di,offset store1
mov cl,[di+2]
add al,30h
add cl,30h
add al,cl
AAA
mov di,offset store2
mov [di+8],al
mov di,offset store1
mov [di+3],ah
mov di,offset num1
mov al,[di+4]
sub al,30h
mul bl
AAM
mov di,offset store1
mov cl,[di+3]
add al,30h
add cl,30h;1st page
add al,cl
AAA
mov di,offset store2
mov [di+7],al
mov di,offset store1
mov [di+4],ah
mov di,offset num1
mov al,[di+3]
sub al,30h
mul bl
AAM
mov di,offset store1
mov cl,[di+4]
add al,30h
add cl,30h
add al,cl
AAA
mov di,offset store2
mov [di+6],al
mov [di+5],ah
mov di,offset num1
mov al,[di+7]
sub al,30h
mov di,offset num2
mov bl,[di+6]
sub bl,30h
mul bl
AAM
;next line
mov di,offset store3
mov [di+9],al;store 1st answer
mov di,offset store1
mov [di+2],ah
mov [di+1],al
mov di,offset num1
mov al,[di+6]
sub al,30h
mul bl
AAM
mov di,offset store1;2nd page
mov cl,[di+2]
add al,30h
add cl,30h
add al,cl
AAA
mov di,offset store3
mov [di+8],al
mov di,offset store1
mov [di+3],ah
mov di,offset num1
mov al,[di+4]
sub al,30h
mul bl
AAM
mov di,offset store1
mov cl,[di+3]
add al,30h
add cl,30h
add al,cl
AAA
mov di,offset store3
mov [di+7],al
mov di,offset store1
mov [di+4],ah
mov di,offset num1
mov al,[di+3]
sub al,30h
mul bl
AAM
mov di,offset store1
mov cl,[di+4]
add al,30h
add cl,30h
add al,cl
AAA
mov di,offset store3
mov [di+6],al
mov [di+5],ah
;next line
mov di,offset num1;3rd page
mov al,[di+7]
sub al,30h
mov di,offset num2
mov bl,[di+4]
sub bl,30h
mul bl
AAM
mov di,offset store4
mov [di+9],al;store 1st answer
mov di,offset store1
mov [di+2],ah
mov [di+1],al
mov di,offset num1
mov al,[di+6]
sub al,30h
mul bl
AAM
mov di,offset store1
mov cl,[di+2]
add al,30h
add cl,30h
add al,cl
AAA
mov di,offset store4
mov [di+8],al
mov di,offset store1
mov [di+3],ah
mov di,offset num1
mov al,[di+4]
sub al,30h
mul bl
AAM
mov di,offset store1
mov cl,[di+3]
add al,30h
add cl,30h
add al,cl
AAA
mov di,offset store4
mov [di+7],al
mov di,offset store1
mov [di+4],ah; 4th page
mov di,offset num1
mov al,[di+3]
sub al,30h
mul bl
AAM
mov di,offset store1
mov cl,[di+4]
add al,30h
add cl,30h
add al,cl
AAA
mov di,offset store4
mov [di+6],al
mov [di+5],ah
;NEXT LINE
mov di,offset num1
mov al,[di+7]
sub al,30h
mov di,offset num2
mov bl,[di+3]
sub bl,30h
mul bl
AAM
mov di,offset store5
mov [di+9],al;store 1st answer
mov di,offset store1
mov [di+2],ah
mov [di+1],al
mov di,offset num1
mov al,[di+6]
sub al,30h
mul bl
AAM
mov di,offset store1
mov cl,[di+2]
add al,30h
add cl,30h
add al,cl
AAA
mov di,offset store5;5th page
mov [di+8],al
mov di,offset store1
mov [di+3],ah
mov di,offset num1
mov al,[di+4]
sub al,30h
mul bl
AAM
mov di,offset store1
mov cl,[di+3]
add al,30h
add cl,30h
add al,cl
AAA
mov di,offset store5
mov [di+7],al
mov di,offset store1
mov [di+4],ah
mov di,offset num1
mov al,[di+3]
sub al,30h
mul bl
AAM
mov di,offset store1
mov cl,[di+4]
add al,30h
add cl,30h
add al,cl
AAA
mov di,offset store5
mov [di+6],al
mov [di+5],ah
;make addition from the store and store the answer
mov di,offset store2
mov al,[di+9]
add al,30h
mov di,offset ans
mov [di+9],al
mov di,offset store2
mov al,[di+8];6th page
add al,30h
mov di,offset store3
mov bl,[di+9]
add bl,30h
add al,bl
AAA
add al,30h
mov di,offset ans
mov [di+8],al
mov bl,ah
add bl,30h
mov di,offset store2
mov al,[di+7]
add al,30h
add al,bl
AAA
mov cl,ah
mov ah,0
mov di,offset store3
mov bl,[di+8]
add al,30h
add bl,30h
add al,bl
AAA
add cl,ah
mov ah,0
mov di,offset store4
mov bl,[di+9]
add al,30h
add bl,30h
add al,bl
AAA
add cl,ah
mov ah,0
mov di,offset ans
add al,30h
mov [di+7],al
mov di,offset store2
mov al,[di+6]
add al,30h
add cl,30h
add al,cl;7th paGE
AAA
mov cl,ah;store carry
mov di,offset store3
mov bl,[di+7]
add bl,30h
add al,30h
add al,bl
AAA
add cl,ah;store the final carry
mov ah,0
mov di,offset store4
mov bl,[di+8]
add bl,30h
add al,30h
add al,bl
AAA
add cl,ah
mov ah,0
mov di,offset store5
mov bl,[di+9]
add bl,30h
add al,30h
add al,bl
AAA
add cl,ah
mov ah,0
mov di,offset ans;store the answer
add al,30h
mov [di+6],al
mov byte ptr [di+5],".";place the floating point
mov di,offset store2
mov al,[di+5]
add al,30h
add cl,30h
add al,cl
AAA
mov cl,ah;store carry
mov di,offset store3
mov bl,[di+6]
add al,30h
add bl,30h
add al,bl;
AAA
add cl,ah
mov ah,0
mov di,offset store4
mov bl,[di+7]
add al,30h
add bl,30h
add al,bl
AAA
add cl,ah
mov ah,0
mov di,offset store5
mov bl,[di+8]
add al,30h
add bl,30h
add al,bl
AAA
add cl,ah
mov ah,0
mov di,offset ans;store answer
add al,30h
mov [di+4],al
mov di,offset store3
mov al,[di+5]
add al,30h
add cl,30h
add al,cl
AAA
mov cl,ah;store carry
mov di,offset store4
mov bl,[di+6]
add al,30h
add bl,30h
add al,bl
AAA
add cl,ah
mov ah,0
mov di,offset store5
mov bl,[di+7]
add al,30h
add bl,30h
add al,bl
AAA;9TH PAGE
add cl,ah
mov ah,0
mov di,offset ans;store answer
add al,30h
add cl,30h
mov [di+3],al
mov [di+2],cl
;look for the sign of the number
mov di,offset num1
mov al,[di+2]
mov di,offset num2
mov bl,[di+2]
cmp al,bl
je positiveans
cmp al,bl
jne negativeans
cmp al,"-"
jne falsesign
cmp al,"+"
jne falsesign
cmp bl,"+"
jne falsesign
cmp bl,"-"
jne falsesign
jmp last1
four:
mov dx,offset message5
mov ah,09h
int 21h
call getnum
mov di,offset num1
mov al,[di+3]
mov ah,0
mov di,offset num2
mov bl,[di+3]
sub bl,30h
sub al,30h
AAD
div bl
mov di,offset store2
mov [di+3],ah
mov di,offset store1
mov [di+3],al;store the 1st answer
mov di,offset num1
mov al,[di+4]
mov di,offset store2
mov ah,[di+3]
sub ax,30h
AAD
div bl
mov di,offset store2
mov [di+4],ah
mov di,offset store1
mov [di+4],al
mov di,offset num1
mov al,[di+6]
mov di,offset store2
mov ah,[di+4]
sub ax,30h
AAD
div bl
mov di,offset store2
mov [di+5],ah;store carry
mov di,offset store1
mov [di+5],al;store ans
mov di,offset num1
mov al,[di+7]
mov di,offset store2
mov ah,[di+5]
sub ax,30h
AAD
div bl
;;;;
mov di,offset store1
mov al,[di+5]
mov ah,[di+4]
add ax,3030h
mov di,offset ans
mov [di+7],al
mov [di+6],ah
mov byte ptr [di+5],"."
mov di,offset store1
mov al,[di+3]
mov ah,[di+2]
add ax,3030h
mov di,offset ans
mov [di+4],al
mov [di+3],ah
call displayans
jmp last1
FIVE:
mov dx,offset message10
mov ah,09h
int 21h
jmp last
getnum proc near
mov dx,offset message7
mov ah,09h
int 21h
mov dx,offset num1
mov ah,0ah
int 21h
mov dx,offset message8
mov ah,09h
int 21h
mov dx,offset num2
mov ah,0ah
int 21h
ret
getnum endp
displayans proc near
mov dx,offset message9
mov ah,09h
int 21h
mov di,offset ans
mov dx,offset ans
mov byte ptr [di+10],24h
mov ah,09h
int 21h
ret
displayans endp
adjustsigned proc near ;only for the subtraction operation
mov di,offset num1
mov al,[di+2]
mov di,offset num2
mov bl,[di+2]
mov di,offset ans
cmp al,bl
je adjustsamesigned
jne adjustnotsamesigned
adjustsamesigned:
mov di,offset num1
mov bh,[di+3]
mov bl,[di+4]
mov di,offset num2
mov ch,[di+3]
mov cl,[di+4]
cmp bx,cx
ja findbiggest1
jna findlowest1
findbiggest1:
mov di,offset num1
mov al,[di+2]
mov di,offset ans
cmp al,"+"
mov byte ptr [di+2],"+"
je startsubtract
cmp al,"-"
mov byte ptr [di+2],"-"
je changevalue
findlowest1:
mov di,offset num1
mov al,[di+2]
mov di,offset ans
cmp al,"+"
mov byte ptr [di+2],"-"
je changevalue
cmp al,"-"
mov byte ptr [di+2],"+"
je changevalue
changevalue:
mov di,offset num1
mov ax,[di+3]
push ax
mov ax,[di+6]
push ax
mov di,offset num2
mov ax,[di+3]
push ax
mov ax,[di+6]
push ax
pop ax
mov di,offset num1
mov [di+6],ax
pop ax
mov [di+3],ax
pop ax
mov di,offset num2
mov [di+6],ax
pop ax
mov [di+3],ax
jmp startsubtract
adjustnotsamesigned:
cmp al,"+"
mov byte ptr [di+2],"+"
je startaddition
cmp al,"-"
mov byte ptr [di+2],"-"
je startaddition
adjustsigned endp
adjustsignedforadd proc near
mov di,offset num1
mov al,[di+2]
mov di,offset num2
mov bl,[di+2]
mov di,offset ans
cmp al,bl
je adjustsamesigned1
jne adjustnotsamesigned1
adjustsamesigned1:
cmp al,"+"
mov byte ptr [di+2],"+"
je startaddition
cmp al,"-"
mov byte ptr [di+2],"-"
je startaddition
adjustnotsamesigned1:
mov di,offset num1
mov bh,[di+3]
mov bl,[di+4]
mov di,offset num2
mov ch,[di+3]
mov cl,[di+4]
cmp bx,cx
ja findbiggest
jna findlowest
findbiggest:
mov di,offset num1
mov al,[di+2]
mov di,offset ans
cmp al,"+"
mov byte ptr [di+2],"+"
je startsubtract
cmp al,"-"
mov byte ptr [di+2],"-"
je startsubtract
findlowest:
mov di,offset num1
mov al,[di+2]
mov di,offset ans
cmp al,"+"
mov byte ptr [di+2],"-"
je changevalue
cmp al,"-"
mov byte ptr [di+2],"+"
je changevalue
adjustsignedforadd endp
positiveans:
mov di,offset ans
mov byte ptr[di+2],"+"
call displayans
jmp last1
negativeans:
mov di,offset ans
mov byte ptr[di+2],"-"
call displayans
jmp last1
falsesign:
mov di,offset ans
mov dx,offset message11
mov ah,09h
int 21h
jmp start
last1:
jmp start
last:
.exit
end start