|
-
Nov 28th, 2008, 11:06 AM
#1
Thread Starter
Hyperactive Member
Question: finding cube of a number
I wrote this to multiply the x by itself 3times then add a number y to it and save result in z. but it dosn't giving me the right result.
Code:
.DATA
X DB 12h
Y DB 34h
Z DW ?,?
mov al,x
mov bl,x
mul bl; ax=bl*al
mul ax; dxax=ax*ax
add ax,y
mov z,ax
mov z+2,bx
I wrote it in Debug.
thank's
-
Nov 28th, 2008, 02:43 PM
#2
Re: Question: finding cube of a number
Is that .NET or Assembly.. or IL ??
-
Nov 28th, 2008, 04:00 PM
#3
Thread Starter
Hyperactive Member
Re: Question: finding cube of a number
It is assembly code dealing with 8086 processor.
I want to find the cube of a number.
My problem, for ex:
MOV AX,0012h;
MUL AX; that will do DXAX=AX*AX
now how can I multiply the DXAX with AX again to get the cube stored in DXAX ?
thank's in advance
-
Dec 6th, 2008, 02:51 PM
#4
Member
Re: Question: finding cube of a number
If x always is 2 i.e 2^3 you can do it like this
Code:
mov eax,2
shl eax,2
Result in eax
If you use mul you do it like this (5^3)
Code:
mov eax,5
mov ecx,2
jmp @F
back:
mov edx,5
mul edx
dec ecx
@@:
cmp ecx,0
ja back
Result in eax
If you use co-processor you do i like this (5^3)
Code:
finit ;Initialize the co-processor
mov eax,0 ;Load
push eax ;3
mov eax,3 ;to stack
push eax ;as a qword
fild qword ptr [esp] ;Load 3 from stack to 80-bit register st(0)=3
add esp,8 ;Restore stack
mov eax,0 ;Load
push eax ;5
mov eax,5 ;to stack
push eax ;as a qword
fild qword ptr [esp] ;Load 5 from stack to next register st(0)=5, st(1)=3
add esp,8 ;Restore stack
fyl2x ;st(0)=st(1)*log2(st(0)) => st(0)=5*log2(3)
fst st(1) ;Store st(1)=st(0)=5*log2(3)
frndint ;Round ST(0) to an integer
fsub st(1),st(0) ;Subtract st(0) from st(1) => st(0)=integer and st(1)=fraction
fxch st(1) ;Exchange st(0) and st(1)
f2xm1 ;computes the exponential value of 2 to the power of the value of ST(0) and subtracts 1
fld1 ;Load value 1 to st(0). st(0)=1, st(1)=2^st(0), st(2)=integer
fadd ;st(0)=2^st(0), st(1)=integer
fscale ;Scale ST(0) by ST(1)
fwait ;Wait while co-processor is busy
fstp fResult ;Store in fResult(qword) and pop ST(0)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|