home projects random project
Goal: 61 / 1000

R100P0610A02 - assembly/02

Static Badge copy

« back 0610A02 next »

This is a part of R100P0917A00 .

Now this is where I get cocky. I now know how to use libraries from my assembler… so what’s stopping me from using GLFW? Now kids, let me remind you – GLFW is a C library. It’s not meant to be used from assembly. Well, I mean it could be, but it’s sort of pointless to use from assembly. That sure didn’t stop me, though. This was also made September 7th, 2023.

Now that I’m using GLFW, you’ll have to do some stuff with your compiler and machine. On my Linux machine, it compiles with: gcc -lglfw -lOpenGL -o program main.s.

	.global main
	.text

title:
	.string "GLFW from ASM: Why Not"

main:
	push 	%rbx		; since we are already using rbx below, ensure stack alignment
	call 	glfwInit
	cmp 	$1, %rax
	jne 	init_fail	; jump straight to end on failure (return code)

	; glfwCreateWindow(int width, int height, char *title, void *monitor, void *share)
	mov 	$640, %edi
	mov 	$480, %esi
	lea 	title(%rip), %rdx
	xor	%ecx, %ecx
	xor 	%r8d, %r8d
	call 	glfwCreateWindow
	mov 	%rax, %rbx	; store window into rbx
	mov 	%rax, %rdi
	call 	glfwMakeContextCurrent

loop:
	; glClear(GL_COLOR_BUFFER_BIT)
	mov 	$0x00004000, %rdi
	call 	glClear
	mov	%rbx, %rdi
	call 	glfwSwapBuffers
	call 	glfwPollEvents

	; glfwWindowShouldClose(void *window)
	mov	%rbx, %rdi
	call 	glfwWindowShouldClose
	test 	%eax, %eax
	je 	loop

	xor 	%eax, %eax
init_fail:
	pop 	%rbx
	ret

Raw file