R100P0610A03 - assembly/03
This is a part of R100P0917A00 .
In a moment of weakness, I lapsed back to C. I thought, in my hubris, that assembly is useless except for parts that need to be really fast. Oh, woe was I, in that feeble moment.
Okay, well, my hubris is right. Most programs don’t need to be all in assembly – you only really need a specific subroutine that has to be fast in assembly. That’s what I wanted to try with this project. I wanted to figure out how to call assembly from C. This project was also made September 7th, 2023.
To compile, surprisingly, there is not many shenannigans required. On my Linux
machine, it compiles with: gcc -lglfw -lOpenGL -o program main.c render.s
.
main.c
:
#include <GLFW/glfw3.h>
extern void render_process();
int main(int argc, char *argv[]) {
if (glfwInit() != GLFW_TRUE) {
return 1;
}
GLFWwindow *window = glfwCreateWindow(640, 480, "GLFW, and ASM", NULL, NULL);
glfwMakeContextCurrent(window);
while (!glfwWindowShouldClose(window)) {
render_process();
glfwSwapBuffers(window);
glfwPollEvents();
}
glfwTerminate();
return 0;
}
render.s
:
.global render_process
.text
one: .float 1.0
render_process:
push %rbp
mov %rsp, %rbp
; glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
movss one(%rip), %xmm0 ; 1.0
pxor %xmm1, %xmm1 ; 0.0
pxor %xmm2, %xmm2 ; 0.0
movss one(%rip), %xmm3 ; 1.0
call glClearColor
; glClear(GL_COLOR_BUFFER_BIT)
mov $0x00004000, %rdi
call glClear
leave
ret