can everyone tell how to write emu8086 to solve this question :
- sum=1+2+3+...+2n-1
- p=1*2*3*...*10
can everyone tell how to write emu8086 to solve this question :
- sum=1+2+3+...+2n-1
- p=1*2*3*...*10
A mathematical formula for 1+2+...+2n-1 is (2n-1)*n , which is easy to program.
The second one is the factorial. Because it gets large very fast, you will get an overflow for very small numbers already, especially in a 16-bit register
(max you can get is 8!). If bigger is needed, you will have to move things in memory.
Here is the code, assuming the input is in AX and the result is too:
; (2n-1)*n
mov dx,ax
shl ax,1
dec ax
mul dx
; factorial
mov cx,ax
mov ax,1
theloop:
mul cx
loop theloop