Advertisement
Guest User

Untitled

a guest
Nov 15th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. ; WINDLX Ex.3: Factorial
  2. ; (c) 1991 Guenther Raidl
  3. ; Modified: 1992 Maziar Khosravipour
  4. ; Program begin at symbol main
  5. ; requires module INPUT
  6. ; read a number from stdin and calculate the factorial (type: double)
  7. ; the result is written to stdout
  8. ;---
  9. .data
  10. Prompt: .asciiz "An integer value >1 : "
  11. PrintfFormat: .asciiz "Factorial = %g\n\n"
  12. .align 2
  13. PrintfPar: .word PrintfFormat
  14. PrintfValue:.space 8
  15. .text
  16. .global main
  17. main:
  18. ;--- Read value from stdin into R1
  19. addi r1,r0,Prompt
  20. jal InputUnsigned
  21. ;--- init values
  22. movi2fp f10,r1 ;R1 -> D0 D0..Count register
  23. cvti2d f0,f10
  24. addi r2,r0,1 ;1 -> D2 D2..result
  25. movi2fp f11,r2
  26. cvti2d f2,f11
  27. movd f4,f2 ;1-> D4 D4..Constant 1
  28. ;--- Break loop if D0 = 1
  29. Loop: led f0,f4 ;D0<=1 ?
  30. bfpt Finish
  31. ;--- Multiplication and next loop
  32. multd f2,f2,f0
  33. subd f0,f0,f4
  34. j Loop
  35. Finish: ;--- write result to stdout
  36. sd PrintfValue,f2
  37. addi r14,r0,PrintfPar
  38. trap 5
  39. ;--- end
  40. trap 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement