Created
September 26, 2018 20:35
-
-
Save theKidOfArcrania/fb7d695d33131c7053f4438b06c55cf0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%include "nasmx.inc" | |
ENTRY main | |
IMPORT fgets | |
IMPORT printf | |
IMPORT puts | |
IMPORT atoi | |
EXTERN stdin | |
section .data | |
numfmt: db "%d", 0xa, 0 | |
input_cap: db "Input cap on the fibonacci numbers: ", 0 | |
fibs: db "Here are the fibonacci numbers up to %d: ", 0 | |
nullstr: db 0 | |
section .text | |
; Prints all the fibonacci numbers up to | |
PROC fibo, uint32_t capFibos | |
LOCALS NONE | |
; To transfer the argument value capFibo into a register just do: | |
; mov rax, [argv(.capFibo)] | |
; To print the number in rax: `INVOKE print_num, rax` | |
; TODO: code for this one. | |
ENDPROC | |
; ********************************************************* | |
; Below this line we have some helper functions You do not need to worry about | |
; any of these functions. | |
; ********************************************************* | |
; Prints a number | |
PROC print_num, uint32_t number | |
; This line will allow you to use any register and not have to worry about | |
; printf overriding those registers. | |
USES rax, rbx, rcx, rdx, rsi, rdi, r9, r8 | |
LOCALS NONE | |
INVOKE printf, numfmt | |
ENDPROC | |
PROC read_num, ptrdiff_t prompt | |
LOCALS | |
LOCAL buff, uint8_t, 80 | |
ENDLOCALS | |
INVOKE printf, [argv(.prompt)] | |
lea rax, [var(.buff)] | |
INVOKE fgets, rax, 80, stdin | |
lea rax, [var(.buff)] | |
INVOKE atoi, rax | |
ENDPROC | |
PROC main | |
LOCALS | |
LOCAL cap, uint32_t | |
ENDLOCALS | |
INVOKE read_num, input_cap | |
mov [var(.cap)], eax | |
INVOKE puts, nullstr | |
INVOKE puts, fibs | |
INVOKE fibo, [var(.cap)] | |
ENDPROC | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment