remove nasm templates
- fix: "Generate assembly" menu item is wrongly enabled for new GNU assembly files
This commit is contained in:
parent
8ad1915acd
commit
410cb50b18
|
@ -691,7 +691,7 @@ void MainWindow::updateCompileActions(const Editor *e)
|
||||||
if (!e->inProject()) {
|
if (!e->inProject()) {
|
||||||
FileType fileType = getFileType(e->filename());
|
FileType fileType = getFileType(e->filename());
|
||||||
if (fileType == FileType::CSource
|
if (fileType == FileType::CSource
|
||||||
|| fileType == FileType::CppSource || e->isNew()) {
|
|| fileType == FileType::CppSource) {
|
||||||
canGenerateAssembly = true;
|
canGenerateAssembly = true;
|
||||||
canCompile = true;
|
canCompile = true;
|
||||||
canRun = true;
|
canRun = true;
|
||||||
|
|
|
@ -2,10 +2,10 @@
|
||||||
Ver = 3
|
Ver = 3
|
||||||
Name = GAS & C
|
Name = GAS & C
|
||||||
Category = Assembly
|
Category = Assembly
|
||||||
Description = C and GAS mixing programming demo
|
Description = C and GNU assembly mixing programming demo
|
||||||
Name[zh_CN] = GAS与C
|
Name[zh_CN] = GAS与C
|
||||||
Category[zh_CN] = 汇编
|
Category[zh_CN] = 汇编
|
||||||
Description[zh_CN] = C和GAS汇编混合编程示例
|
Description[zh_CN] = C和GNU汇编混合编程示例
|
||||||
Icon = app.ico
|
Icon = app.ico
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
Ver = 3
|
Ver = 3
|
||||||
Name = Hello GAS
|
Name = Hello GAS
|
||||||
Category = Assembly
|
Category = Assembly
|
||||||
Description = A simple GNU as program
|
Description = A simple GNU assembly program
|
||||||
Name[zh_CN] = GAS你好
|
Name[zh_CN] = GAS你好
|
||||||
Category[zh_CN] = 汇编
|
Category[zh_CN] = 汇编
|
||||||
Description[zh_CN] = 简单的GNU汇编程序示例
|
Description[zh_CN] = 简单的GNU汇编程序示例
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 4.2 KiB |
|
@ -1,22 +0,0 @@
|
||||||
[Template]
|
|
||||||
Ver = 3
|
|
||||||
Name = Hello NASM
|
|
||||||
Category = NASM
|
|
||||||
Description = A simple nasm program
|
|
||||||
Name[zh_CN] = NASM你好
|
|
||||||
Category[zh_CN] = NASM
|
|
||||||
Description[zh_CN] = 简单的NASM汇编程序示例
|
|
||||||
Icon = app.ico
|
|
||||||
|
|
||||||
|
|
||||||
[Project]
|
|
||||||
Type = 1
|
|
||||||
IsCpp = true
|
|
||||||
Encoding = UTF-8
|
|
||||||
ClassBrowserType = 0
|
|
||||||
UnitCount = 1
|
|
||||||
|
|
||||||
|
|
||||||
[Unit0]
|
|
||||||
Source = main.asm
|
|
||||||
Target = main.asm
|
|
|
@ -1,26 +0,0 @@
|
||||||
extern printf
|
|
||||||
extern exit
|
|
||||||
global main
|
|
||||||
|
|
||||||
section .data ; Data section, initialized variables
|
|
||||||
msg: db "Hello world", 0 ; C string needs 0
|
|
||||||
fmt: db "%s", 10, 0 ; The printf format, "\n",'0'
|
|
||||||
|
|
||||||
section .text:
|
|
||||||
main:
|
|
||||||
; Microsoft X86_64 Calling convention:
|
|
||||||
; - The first four integer or pointer parameters are passed in the rcx, rdx, r8, and r9 registers.
|
|
||||||
; - The first four floating-point parameters are passed in the first four SSE registers, xmm0-xmm3.
|
|
||||||
; - The caller reserves space on the stack for arguments passed in registers. The called function can use this space to spill the contents of registers to the stack.
|
|
||||||
; - Any additional arguments are passed on the stack.
|
|
||||||
; - An integer or pointer return value is returned in the rax register, while a floating-point return value is returned in xmm0.
|
|
||||||
; see https://learn.microsoft.com/en-us/windows-hardware/drivers/debugger/x64-architecture
|
|
||||||
|
|
||||||
sub rsp, 32 ; reserve stack space for call
|
|
||||||
lea rcx, [rel fmt] ; first parameter
|
|
||||||
lea rdx, [rel msg] ; secodng parameter
|
|
||||||
call printf
|
|
||||||
add rsp,32 ; restore stack
|
|
||||||
|
|
||||||
mov eax,0 ; exit code
|
|
||||||
ret
|
|
Binary file not shown.
Before Width: | Height: | Size: 4.2 KiB |
|
@ -1,27 +0,0 @@
|
||||||
[Template]
|
|
||||||
Ver = 3
|
|
||||||
Name = NASM & C
|
|
||||||
Category = NASM
|
|
||||||
Description = C and NASM mixing programming demo
|
|
||||||
Name[zh_CN] = NASM与C
|
|
||||||
Category[zh_CN] = NASM
|
|
||||||
Description[zh_CN] = C和NASM汇编混合编程示例
|
|
||||||
Icon = app.ico
|
|
||||||
|
|
||||||
|
|
||||||
[Project]
|
|
||||||
Type = 1
|
|
||||||
IsCpp = true
|
|
||||||
Encoding = UTF-8
|
|
||||||
ClassBrowserType = 0
|
|
||||||
UnitCount = 2
|
|
||||||
|
|
||||||
|
|
||||||
[Unit0]
|
|
||||||
Source = utils.asm
|
|
||||||
Target = utils.asm
|
|
||||||
|
|
||||||
|
|
||||||
[Unit1]
|
|
||||||
Cpp = main.cpp
|
|
||||||
CppName = main.cpp
|
|
|
@ -1,26 +0,0 @@
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
#define ASM_FUNC extern "C"
|
|
||||||
#else
|
|
||||||
#define ASM_FUNC
|
|
||||||
#endif
|
|
||||||
|
|
||||||
ASM_FUNC int maxofthree(int, int, int);
|
|
||||||
ASM_FUNC int add3(int, int, int);
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
printf("%d\n", add3(1, -4, -7));
|
|
||||||
printf("%d\n", add3(1, 2, 3));
|
|
||||||
printf("%d\n", add3(2, -6, 1));
|
|
||||||
|
|
||||||
printf("------\n");
|
|
||||||
|
|
||||||
printf("%d\n", maxofthree(1, -4, -7));
|
|
||||||
printf("%d\n", maxofthree(2, -6, 1));
|
|
||||||
printf("%d\n", maxofthree(2, 3, 1));
|
|
||||||
printf("%d\n", maxofthree(-2, 4, 3));
|
|
||||||
printf("%d\n", maxofthree(2, -6, 5));
|
|
||||||
printf("%d\n", maxofthree(2, 4, 6));
|
|
||||||
return 0;
|
|
||||||
}
|
|
|
@ -1,15 +0,0 @@
|
||||||
global maxofthree
|
|
||||||
global add3
|
|
||||||
section .text
|
|
||||||
maxofthree:
|
|
||||||
mov eax, ecx ; result (rax) initially holds x
|
|
||||||
cmp eax, edx ; is x less than y?
|
|
||||||
cmovl eax, edx ; if so, set result to y
|
|
||||||
cmp eax, r8d ; is max(x,y) less than z?
|
|
||||||
cmovl eax, r8d ; if so, set result to z
|
|
||||||
ret ; the max will be in rax
|
|
||||||
add3:
|
|
||||||
mov eax, ecx
|
|
||||||
add eax, edx
|
|
||||||
add eax, r8d
|
|
||||||
ret
|
|
|
@ -40,56 +40,46 @@ int main()
|
||||||
glViewport(0, 0, WIDTH, HEIGHT);
|
glViewport(0, 0, WIDTH, HEIGHT);
|
||||||
|
|
||||||
|
|
||||||
//读取shader文件,并编译,见shader.h代码
|
|
||||||
Shader ourShader("shader.vs", "shader.frag");
|
Shader ourShader("shader.vs", "shader.frag");
|
||||||
|
|
||||||
|
|
||||||
// 一维数组,每六个代表一个顶点属性,前三个代表位置属性,后三个代表颜色属性
|
|
||||||
GLfloat vertices[] = {
|
GLfloat vertices[] = {
|
||||||
// Positions // Colors
|
// Positions // Colors
|
||||||
0.5f, -0.5f, 0.0f, 1.0f, 0.0f, 0.0f, // Bottom Right
|
0.5f, -0.5f, 0.0f, 1.0f, 0.0f, 0.0f, // Bottom Right
|
||||||
-0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 0.0f, // Bottom Left
|
-0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 0.0f, // Bottom Left
|
||||||
0.0f, 0.5f, 0.0f, 0.0f, 0.0f, 1.0f // Top
|
0.0f, 0.5f, 0.0f, 0.0f, 0.0f, 1.0f // Top
|
||||||
};
|
};
|
||||||
GLuint VBO, VAO;//声明顶点缓冲,声明顶点数组用于管理顶点数据
|
GLuint VBO, VAO;
|
||||||
glGenVertexArrays(1, &VAO);//创建顶点数组,返回一个独一无二的整数,标识数组
|
glGenVertexArrays(1, &VAO);
|
||||||
glGenBuffers(1, &VBO);//创建顶点缓冲,返回一个独一无二的整数,标识缓冲区
|
glGenBuffers(1, &VBO);
|
||||||
|
|
||||||
glBindVertexArray(VAO);//绑定顶点数组
|
glBindVertexArray(VAO);
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, VBO);//绑定顶点缓冲
|
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
||||||
//指定顶点数组的数据源为vertices,第四个参数代表显卡如何管理给定的数据,GL_STATIC_DRWA代表几乎不会改变
|
|
||||||
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
|
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
|
||||||
|
|
||||||
// 指定顶点属性的解析方式。即,如何从顶点缓冲获取相应的顶点属性和相应的颜色属性。或者说,顶点着色器中如何知道去哪个顶点属性分量重着色呢
|
|
||||||
//对每一个顶点而言,属性有2种,一是位置属性,而是颜色属性,因此每六个浮点数决定了一个顶点的位置和颜色
|
|
||||||
|
|
||||||
//顶点着色器中使用layout(location = 0)定义了position顶点属性的位置值(Location),因此第一个参数,代表属性分量的索引
|
|
||||||
//参数二:顶点位置属性的维度,参数三:属性向量的数据类型,参数四:是否标准化;参数五,顶点位置属性的总字节长度,参数六:在缓冲数组中的偏移量,即起始位置
|
|
||||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat), (GLvoid*)0);
|
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat), (GLvoid*)0);
|
||||||
glEnableVertexAttribArray(0);//启用属性0,因为默认是禁用的
|
glEnableVertexAttribArray(0);
|
||||||
|
|
||||||
// 参数一,对应顶点着色器中的layout (location = 1) in vec3 color;参数六:说明颜色属性的偏移量在三个浮点数后,与上文vertices一致
|
|
||||||
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat), (GLvoid*)(3 * sizeof(GLfloat)));
|
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat), (GLvoid*)(3 * sizeof(GLfloat)));
|
||||||
glEnableVertexAttribArray(1);//启用属性1.
|
glEnableVertexAttribArray(1);
|
||||||
|
|
||||||
|
glBindVertexArray(0);
|
||||||
|
|
||||||
//顶点数组对象(Vertex Array Object, VAO)的好处就是,当配置顶点属性指针时,你只需要将上面的代码调用执行一次,之后再绘制物体的时候只需要绑定相应的VAO就行了。如下文循环中的绑定再解绑
|
|
||||||
glBindVertexArray(0); // 解绑 VAO
|
|
||||||
// Game loop
|
// Game loop
|
||||||
while (!glfwWindowShouldClose(window))
|
while (!glfwWindowShouldClose(window))
|
||||||
{
|
{
|
||||||
// 检查事件,调用相应的回调函数,如下文的key_callback函数
|
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
|
|
||||||
// Render
|
// Render
|
||||||
// Clear the colorbuffer
|
// Clear the colorbuffer
|
||||||
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);//渲染颜色到后台缓冲
|
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
|
||||||
glClear(GL_COLOR_BUFFER_BIT);//清除前台缓冲
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
// Draw the triangle
|
// Draw the triangle
|
||||||
ourShader.Use();//启用着色器程序
|
ourShader.Use();
|
||||||
glBindVertexArray(VAO);//每次循环都调用,绑定函数绑定VAO
|
glBindVertexArray(VAO);
|
||||||
glDrawArrays(GL_TRIANGLES, 0, 3);
|
glDrawArrays(GL_TRIANGLES, 0, 3);
|
||||||
glBindVertexArray(0);//解绑
|
glBindVertexArray(0);
|
||||||
|
|
||||||
// Swap the screen buffers
|
// Swap the screen buffers
|
||||||
glfwSwapBuffers(window);
|
glfwSwapBuffers(window);
|
||||||
|
|
|
@ -50,18 +50,18 @@ public:
|
||||||
GLint success;
|
GLint success;
|
||||||
GLchar infoLog[512];
|
GLchar infoLog[512];
|
||||||
// Vertex Shader
|
// Vertex Shader
|
||||||
vertex = glCreateShader(GL_VERTEX_SHADER);//创建顶点着色器
|
vertex = glCreateShader(GL_VERTEX_SHADER);
|
||||||
glShaderSource(vertex, 1, &vShaderCode, NULL);//指定源代码
|
glShaderSource(vertex, 1, &vShaderCode, NULL);
|
||||||
glCompileShader(vertex);//编译着色器
|
glCompileShader(vertex);
|
||||||
// Print compile errors if any
|
// Print compile errors if any
|
||||||
glGetShaderiv(vertex, GL_COMPILE_STATUS, &success);//查看是否编译成功
|
glGetShaderiv(vertex, GL_COMPILE_STATUS, &success);
|
||||||
if (!success)
|
if (!success)
|
||||||
{
|
{
|
||||||
glGetShaderInfoLog(vertex, 512, NULL, infoLog);
|
glGetShaderInfoLog(vertex, 512, NULL, infoLog);
|
||||||
std::cout << "ERROR::SHADER::VERTEX::COMPILATION_FAILED\n" << infoLog << std::endl;
|
std::cout << "ERROR::SHADER::VERTEX::COMPILATION_FAILED\n" << infoLog << std::endl;
|
||||||
}
|
}
|
||||||
// Fragment Shader
|
// Fragment Shader
|
||||||
fragment = glCreateShader(GL_FRAGMENT_SHADER);//创建片段着色器
|
fragment = glCreateShader(GL_FRAGMENT_SHADER);
|
||||||
glShaderSource(fragment, 1, &fShaderCode, NULL);
|
glShaderSource(fragment, 1, &fShaderCode, NULL);
|
||||||
glCompileShader(fragment);
|
glCompileShader(fragment);
|
||||||
// Print compile errors if any
|
// Print compile errors if any
|
||||||
|
@ -72,10 +72,10 @@ public:
|
||||||
std::cout << "ERROR::SHADER::FRAGMENT::COMPILATION_FAILED\n" << infoLog << std::endl;
|
std::cout << "ERROR::SHADER::FRAGMENT::COMPILATION_FAILED\n" << infoLog << std::endl;
|
||||||
}
|
}
|
||||||
// Shader Program
|
// Shader Program
|
||||||
this->Program = glCreateProgram();//创建着色程序
|
this->Program = glCreateProgram();
|
||||||
glAttachShader(this->Program, vertex);//关联顶点着色器
|
glAttachShader(this->Program, vertex);
|
||||||
glAttachShader(this->Program, fragment);//关联片段着色器
|
glAttachShader(this->Program, fragment);
|
||||||
glLinkProgram(this->Program);//链接编译器
|
glLinkProgram(this->Program);
|
||||||
// Print linking errors if any
|
// Print linking errors if any
|
||||||
glGetProgramiv(this->Program, GL_LINK_STATUS, &success);
|
glGetProgramiv(this->Program, GL_LINK_STATUS, &success);
|
||||||
if (!success)
|
if (!success)
|
||||||
|
|
|
@ -10,10 +10,12 @@ Category[zh_CN]=3D
|
||||||
[Unit0]
|
[Unit0]
|
||||||
CppName=main.cpp
|
CppName=main.cpp
|
||||||
Cpp=GLFW_main.cpp.txt
|
Cpp=GLFW_main.cpp.txt
|
||||||
|
Cpp[zh_CN]=GLFW_main_zh_CN.cpp
|
||||||
|
|
||||||
[Unit1]
|
[Unit1]
|
||||||
CppName=shader.h
|
CppName=shader.h
|
||||||
Cpp=GLFW_shader.h.txt
|
Cpp=GLFW_shader.h.txt
|
||||||
|
Cpp[zh_CN]=GLFW_shader_zh_CN.h
|
||||||
|
|
||||||
[Unit2]
|
[Unit2]
|
||||||
CppName=shader.frag
|
CppName=shader.frag
|
||||||
|
@ -32,7 +34,7 @@ CppCompiler=
|
||||||
Linker=-lglfw3 -lglew32 -lopengl32 -lwinmm -lgdi32_@@__@@_
|
Linker=-lglfw3 -lglew32 -lopengl32 -lwinmm -lgdi32_@@__@@_
|
||||||
CompilerSettings=0000000000110000000001000
|
CompilerSettings=0000000000110000000001000
|
||||||
CompilerSet=1
|
CompilerSet=1
|
||||||
UseUTF8=0
|
Encoding = UTF-8
|
||||||
StaticLink=1
|
StaticLink=1
|
||||||
AddCharset=1
|
AddCharset=1
|
||||||
IncludeVersionInfo=0
|
IncludeVersionInfo=0
|
||||||
|
|
Loading…
Reference in New Issue