Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %assign STDIN 0
- %assign STDOUT 1
- ; Printing macro
- ; 1: Address of the content
- ; 2: Length of the content
- ; 3: File Descriptor of the output
- %macro RFM_PRINT 3
- MOV ECX, %1
- MOV EDX, %2
- MOV EAX, 4
- MOV EBX, %3
- INT 80H
- %endmacro
- ; Reading macro
- ; 1: File Descriptor of the output
- ; 2: Pointer to the string
- ; 3: MaxSize
- %macro RFM_READ 3
- mov EAX, 3
- mov EBX, %1
- mov ECX, %2
- mov EDX, %3
- INT 80H
- %endmacro
- ; Exit macro
- ; 1: Exit Status Code
- %macro RFM_EXIT 1
- mov EBX, %1
- mov EAX, 1
- INT 80H
- %endmacro
- SECTION .data
- fat: equ 12
- SECTION .bss
- string : resb 5
- SECTION .text
- global _start
- _start:
- mov ESI, fat
- inc ESI
- mov EAX, 1
- mov ECX, 1
- LOOP_FATORIAL:
- cmp ECX, ESI
- je END_LOOP_FATORIAL
- mul ECX
- inc ECX
- jmp LOOP_FATORIAL
- END_LOOP_FATORIAL:
- ; EAX tem o fatorial
- mov ESI, 10
- mov ECX, 0 ; ECX contém o tamanho do número
- NUMBER_TO_STRING:
- cmp EAX, 0
- je END_NUMBER_TO_STRING
- inc ECX
- mov EDX, 0
- div ESI
- add EDX, 48
- push EDX
- jmp NUMBER_TO_STRING
- END_NUMBER_TO_STRING:
- cmp ECX, 0
- jne IF_NOT_ZERO
- inc ECX
- IF_NOT_ZERO:
- mov ESI, ECX
- PRINT_STRING_NUMBER:
- cmp ESI, 0
- je END_PRINT_STRING_NUMBER
- dec ESI
- pop EDX
- mov [string], byte DL
- RFM_PRINT string, 1, STDOUT
- jmp PRINT_STRING_NUMBER
- END_PRINT_STRING_NUMBER:
- RFM_EXIT 0
Add Comment
Please, Sign In to add comment