Asmblue/exercice.S

126 lines
2.5 KiB
ArmAsm

;; this macro will save the stack base pointer on the stack so we can safely
;; use call again without breaking "retn" instruction
;; we restore it with instruction "leave" ("pop rbp" works too)
;; we also set rbp to the current stack (which is set to rbp+parameters size)
%macro enter 0
push rbp
mov rbp, rsp
%endmacro
;; --- RO STATIC SEGMENT
section .data
title: DB "Exercice.S", 0
title_eol: DB `Exercice.S\n`, 0
debug_return: DB "Debug: %s = %d", 0
str_glfwInit: DB "glfwInit", 0
str_exiting_properly: DB `Properly closing the process now\n`
;; --- RW STATIC 0 FILLED SEGMENT
section .bss
window: RESQ 1
width: RESD 1
height: RESD 1
;; --- executable code segment ---
section .text
extern exit, printf, sleep
extern glfwInit, glfwTerminate, glfwCreateWindow, glfwMakeContextCurrent, glfwWindowShouldClose
extern glClearColor, glClear, glfwSwapBuffers, glfwPollEvents, glBegin, glEnd, glFlush, glViewport
extern glColor3f, glVertex2f, glfwGetFramebufferSize
global _start
default rel
_start:
call initialize_windows
mov rdi, 0
call exit
initialize_windows:
enter
mov rdi, title_eol
call printf
;; glfwinit()
call glfwInit wrt ..plt
;; glfwcreatewindow()
mov rdi, 800
mov rsi, 600
mov rdx, title
mov rcx, 0
mov r8, 0
call glfwCreateWindow wrt ..plt
mov [window], rax
;; glfwmakecontextcurrent()
mov rdi, [window]
call glfwMakeContextCurrent
mov rdi, __float32__(0.1) ; red
mov rsi, __float32__(0.1) ; green
mov rdx, __float32__(0.1) ; blue
mov rcx, __float32__(0.0) ; alpha
call glClearColor
main_loop:
mov rdi, [window]
lea rsi, [width]
lea rdx, [height]
call glfwGetFramebufferSize
mov rdi, 0
mov rsi, 0
mov rdx, [width]
mov rcx, [height]
call glViewport
mov rdi, 0x00004000 ; GL_COLOR_BUFFER_BIT
call glClear
mov rdi, 0x0004 ; GL_TRIANGLES
call glBegin
mov rdi, __float32__(0.0)
mov rdi, __float32__(0.0)
mov rdx, __float32__(0.0)
call glColor3f
mov rdi, __float32__(0.0)
mov rsi, __float32__(-1.0)
call glVertex2f
mov rdi, __float32__(-1.0)
mov rsi, __float32__(1.0)
call glVertex2f
mov rdi, __float32__(1.0)
mov rsi, __float32__(1.0)
call glVertex2f
call glEnd
call glFlush
mov rdi, [window]
call glfwSwapBuffers
call glfwPollEvents
mov rdi, [window]
call glfwWindowShouldClose
;; "infinite loop" until event
cmp rax, 0
je main_loop
call glfwTerminate
mov rdi, 1
call sleep
mov rdi, str_exiting_properly
call printf wrt ..plt
leave
retn