ioCalls.asm

URL: https://mirkwood.cs.edinboro.edu/~bennett/class/cmsc3100/spring2026/notes/intro/code/ioCalls.asm
 
%define MY_ROUTINES
%include "CONSTANTS.h"

global CallScanf
global CallPrintf
global Flush
global Exit

extern printf
extern scanf
extern fflush

section .text

; rdi holds the format string
; rsi holds the first parameter
; rdx holds the second
; rcx the third.
; r8
; r9
; then on the stack.
CallScanf:
    push rbp
    mov rbp, rsp
    sub rsp, 8

    call scanf

    mov rsp, rbp
    pop rbp

    ret


; make sure the put a null in rdi to flush all open streams.
Flush: 
    push rbp
    mov rbp, rsp
    sub rsp, 8

    mov rax, 0
    call fflush

    mov rsp, rbp
    pop rbp

    ret

CallPrintf:
    push rbp
    mov rbp, rsp
    sub rsp, 8

    mov rax, 0
    call printf

    mov rsp, rbp
    pop rbp
    ret

Exit:
    mov       rax, SYS_EXIT     ; system call for exit
    mov       rdi, SUCCESS      ; exit code 0
    syscall