الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

Calculator using registers only

مغلق
بدأه إبراهيم دويكات في 22 أبريل 2006 · 6 رد · 698 مشاهدة · في لغة Assembly لأنظمة 16, 32, 64 بت
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

Hello everybody

I need a simple calculator which can do (addition,subtraction, multiplication and division) only using registers, no use of memory.....

I am waiting for this one....please help me as soon as possible..........

calc.txt

My_Sign.jpg
#2

راجع هنا: /index.ph...unce&f=79&id=11

قم بوضع محاولاتك.. والا سيغلق الموضوع.

Do as I say, not as I do

We are Anonymous. We are Legion. We don't forgive. We don't forget

#3

This is my try

I used memory

.model SMALL
.data

num1 db 100 dup(?)
num2 db 100 dup(?)
n1 dw 0
n2 dw 0
result db 100 dup (?)
res dw 0

.code
.startup

begin:

mov di,00h

read1:
mov ah,01h
int 21h
cmp al,' '
je read1
cmp al,'0'
jl other
cmp al,'9'
jg other
sub al,30h
mov num1[di],al
inc di
jmp read1

other:
cmp al,'+'
je other2 

cmp al,'-'
je other2 

cmp al,'*'
je other2  

cmp al,'/'
je other2  

jmp endofprogram

other2:
cbw
mov cx,ax
mov num1[di],'$'

nu2: mov si,00h
read2:
mov ah,01h
int 21h
cmp al,' '
je read2
cmp al,'0'
jl main
cmp al,'9'
jg main
sub al,30h
mov num2[si],al
inc si
jmp read2

main:
cmp al,'='
je next
jmp endofprogram

next: mov num2[si],'$'
mov bl,0ah
mov dx,00
mov di,00
mov ax,00
lp:cmp num1[di],'$'
je done1
mul bl
mov dx,ax
mov al,num1[di]
cbw
add ax,dx
inc di
jo printerror
jmp lp

done1:cbw
mov n1,ax
mov dx,00
mov di,00
mov ax,00

lp2:cmp num2[di],'$'
je done2
mul bl
mov dx,ax
mov al,num2[di]
cbw
add ax,dx
inc di
jo printerror
jmp lp2

done2:
cbw
mov n2,ax

cmp cx,'+'
je addnum
cmp cx,'-'
je subnum
cmp cx,'*'
je multnum
cmp cx,'/'
je divvnum
jmp endofprogram

addnum:
mov ax,n1
mov bx,n2
add ax,bx
jo printerror
mov res,ax
jmp print

subnum:
mov ax,n1
sub ax,n2
jo printerror
mov res,ax
jmp print

multnum:
mov ax,n1
mov bx,n2
cwd
mul bx
jo printerror
mov res,ax
jmp print

printerror:
jmp endofprogram

divvnum:
mov ax,n1
cwd
mov bx,n2
div bx
jo printerror
mov res,ax
push dx
cmp dx,00h
jnz print1
jmp print

print:
mov si,00h
mov bx,0ah
mov ax,res
store: cwd
div bx
add dl,30h
mov result[si],dl
cmp ax,00
je displayres
inc si
jmp store


print1:
mov si,00h
mov bx,0ah
mov ax,res
store1: cwd
div bx
add dl,30h
mov result[si],dl
cmp ax,00
je go
inc si
jmp store1

go:
inc si
mov cx,si
mov bx,0ah
pop ax
again:  cwd
inc si
div bx
add dl,30h
mov result[si],dl
cmp ax,00h
je display1
jmp again

display1:
inc si
mov result[si],'$'
jmp display2

display2:
mov si,00h


jmp dis1



dis1:
mov dl,result[si]
cmp dl,'$'
je finish
cmp cx,si
je printmsg
mov ah ,02h
int 21h
inc si
jmp dis1

printmsg:

inc si
jmp dis1

displayres:


 dis:
mov dl,result[si]
mov ah,02h
int 21h
cmp si,00
je finish
dec si
jmp dis

finish:

endofprogram:
.exit

end
My_Sign.jpg
#4

أخي إبراهيم دويكات

أكتب بالعربي لكي تجد من يرد عليك

d4baa0.gif
#5

أعتذر أخي DeltaAziz...........

تم حل المشكلة باستخدام الحاسبة الموجودة حاليا

My_Sign.jpg
#6

انا لم استوعب فكرة "استخدم المسجلات فقط" دون الذاكرة.. في هذه الحالة لن يكون بامكانك التعامل سوى مع ارقام من خانتين فقط لان المسجلات بالاصل لن تخزن لك اكثر من هذا.. ايضا بخصوص هذه العبارة "تم حل المشكلة باستخدام الحاسبة الموجودة حاليا" هل تعني ان الموضوع خلاص انتهى على خير؟

Do as I say, not as I do

We are Anonymous. We are Legion. We don't forgive. We don't forget

#7

نعم أخ Xacker

شكرا لتفاعلك.....كتن بحاجة لاستهدام Registers والـStack فقط، لكن الان لا اريد ذلك........

استخدام memory يريح كثيرا

بارك الله فيكم

My_Sign.jpg

هذا الموضوع مغلق.

مواضيع مشابهة