今天,我決定制作一個(非常)簡單的作業系統。我不想直接使用匯編,因為我認為它對我來說太亂了。但是,我知道一點C,我渴望學習更多。我做了一個簡單的程式來列印一個字串,我想把它編譯成匯編。我用這個命令編譯成程式集:
gcc -S foo.c
這是我的 C 代碼:
#include<stdio.h>
int main() {
printf("Hi!!!");
}
但是當我嘗試運行輸出檔案(foo.s)時,我得到了這些錯誤:
foo.s:1: error: parser: instruction expected
foo.s:2: warning: label alone on a line without a colon might be in error [-w label-orphan]
foo.s:3: error: parser: instruction expected
foo.s:5: error: parser: instruction expected
foo.s:6: warning: label alone on a line without a colon might be in error [-w label-orphan]
foo.s:7: error: parser: instruction expected
foo.s:8: error: parser: instruction expected
foo.s:11: warning: label alone on a line without a colon might be in error [-w label-orphan]
foo.s:12: error: parser: instruction expected
foo.s:13: error: parser: instruction expected
foo.s:14: error: parser: instruction expected
foo.s:15: error: expression syntax error
foo.s:16: error: parser: instruction expected
foo.s:17: error: parser: instruction expected
foo.s:18: error: parser: instruction expected
foo.s:20: error: label `movl' inconsistently redefined
foo.s:18: info: label `movl' originally defined here
foo.s:20: error: parser: instruction expected
foo.s:21: error: parser: instruction expected
foo.s:22: error: parser: instruction expected
foo.s:24: warning: label alone on a line without a colon might be in error [-w label-orphan]
foo.s:26: error: parser: instruction expected
foo.s:27: error: parser: instruction expected
foo.s:28: error: parser: instruction expected
這是我為編譯匯編代碼而運行的命令:
nasm -f bin -o foo.bin foo.s
這是中的匯編代碼foo.s:
.file "foo.c"
.text
.section .rodata
.LC0:
.string "Hi!!!"
.text
.globl main
.type main, @function
main:
.LFB0:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
leaq .LC0(%rip), %rdi
movl $0,
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/408729.html
標籤:
上一篇:macOS:C 11編譯錯誤,Appleclang版本13在終端中但在Xcode中沒有
下一篇:這組指令有什么作用?
