Jump to content
knoxpt

[Assembly486] Factorial e Potencias

Recommended Posts

knoxpt

Ola,

Estou a realizar um projecto em que recebe dois numeros passado pelo cliente e realiza diversas operações no entanto no factorial e na Potencia os resultados não estão correctos.

Na Potencia o primeiro numero é a base e o segundo expoente no factorial apenas é feito o factorial do primeiro numero.

Podem ajudar-me ?

Obrigado desde já pela possibilidade.

;Factorial
FAT:
cmp al,'F'
jne potencia
lodsb
cmp  al,'A'
jne  ERROR
;Factorial do 1 numero
mov bx, [num1]
call  proc_fact
add   ax, 30h
mov  [result], ax
jmp fim_operacao
proc_fact:
	 cmp   bl, 1
 jg    do_calculation
 mov   ax, 1
 ret

do_calculation:
   dec   bl
   call  proc_fact
   inc   bl
   mul   bl	    ;ax = al * bl
   jo fim_operacao
   ret
;Potencia
potencia:
cmp al,'P'
jne funcao_S
lodsb
cmp  al, 'O'
jne  ERROR


call  proc_fact
mov eax, [num1]
mov ebx, [num2]
add edx, eax
call  potenc
potenc:
mul
 jo fim_operacao
 sub ebx,1
 cmp ebx,0
  jnz potenc
 mov [result], al
 jmp fim_operacao

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.