阿狸631 2023-03-20 10:47 采纳率: 100%
浏览 152
已结题

ubuntu18.04 makefile:13: recipe for target 'run' failed

做伪代码翻译成汇编语言时,遇到了如下错误:

li***@VirtualBox:~/lab2/assignment$ make run
>>> begin test
makefile:13: recipe for target 'run' failed
make: *** [run] 段错误 (core dumped)

在网上找了很多办法都解决不了,可以告诉我究竟是哪里出错了吗?
makefile文件内容如下:

TARTGET = test

AS = nasm
CXX = g++

ASM_FILE = $(wildcard *.asm)
CXX_FILE = $(wildcard *.cpp)

ALL_OBJ += $(ASM_FILE:%.asm=%.o)
ALL_OBJ += $(CXX_FILE:%.cpp=%.o)

run:
    @rm -rf *.o
    @nasm -f elf32 $(ASM_FILE)
    @g++ -m32 -g -c $(CXX_FILE)
    @g++ -m32 -o $(TARTGET) $(ALL_OBJ)
    @./$(TARTGET)
clean:
    @rm -rf *.o

我自己编写的汇编文件student.asm如下:

; If you meet compile error, try 'sudo apt install gcc-multilib g++-multilib' first

%include "head.include"
; you code here
.data:
string db 1024 dup(0)
count equ $-string

.code:
mov ecx,if_flag
mov ebx,string

your_if:
mov eax,a1
cmp eax,12
jnl ope1
mov ebx,2
idiv ebx
inc eax
jmp Exit

ope1:
cmp eax,24
jng ope2
mov edx,eax
neg eax
add eax,24
imul eax,edx
jmp Exit

ope2:
shl eax,4
jmp Exit

Exit:
ret

your_while:
mov ecx,a2
mov ebx,while_flag
Loop:
call my_random
mov [ebx+ecx-12],eax
sub ecx,1
cmp ecx,12
jge Loop
mov eax,ebx
ret

%include "end.include"

your_function:
mov edx,0
mov ebx,string
for:
cmp word [ebx+edx],'\0'
je exit
add edx,1
pushad
mov eax,[ebx+edx]
push eax
call print_a_char
pop eax
popad
jmp for
exit:
ret

测试文件test.cpp代码如下:

#include <iostream>

#include <cstdlib>

#include <cstring>

#include <iomanip>



#define RAND_WIDTH 26

extern "C" void student_function();

extern "C" void your_function();

int if_flag, a1, a2;

const char *your_string = "Mr.Chen, students and TAs are the best!\n";

char *while_flag, *random_buffer;


// THE ONLY CODE YOU CAN CHANGE IN THIS FILE!!!

void student_setting() {

    a1 = 24;

    a2 = 14;

}

extern "C" char my_random() {

    char c = rand() % (RAND_WIDTH) + 'a';

    random_buffer[a2 - 12] = c;

    return c;

}

extern "C" void print_a_char(char c) {

    std::cout << c;

}

void test_failed() {

            std::cout << ">>> test failed" << std::endl;

            exit(0);

}

int main() {

    student_setting();

    // init

    std::cout << ">>> begin test" << std::endl;

    if_flag = 0;



    if(a2 >= 12) {

        while_flag = new char[a2 - 12 + 1];

        random_buffer = new char[a2 - 12 + 1];

        if(!while_flag || !random_buffer) {

            std::cout << "test can not run" << std::endl;

            exit(-1);

        }

        memset(while_flag, 0, a2 - 12 + 1);

        memset(random_buffer, 0, a2 - 12 + 1);

    }
    student_function();

    if(a1 < 12) {

        if (if_flag != a1 / 2 + 1) {

            test_failed();

        }

    } else if(a1 < 24) {

        if (if_flag != (24 - a1) * a1) {

            test_failed();

        }

    } else {

        if (if_flag != a1 << 4) {

            test_failed();

        }
    }
    std::cout << ">>> if test pass!" << std::endl;
    if(strcmp(while_flag, random_buffer) == 0 && a2 < 12) {

        std::cout << ">>> while test pass!" << std::endl;

    } else {

        test_failed();

    }
    your_function();

}

head.include代码如下:

global student_function
global your_function

extern a1
extern a2
extern my_random
extern your_string
extern if_flag
extern while_flag
extern print_a_char

student_function:
    pushad

end.include代码如下:

student_function_end:
    popad
    ret
  • 写回答

5条回答 默认 最新

  • 阿狸631 2023-03-27 09:18
    关注

    已解决,汇编文件出了问题,导致makefile出现段错误

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

问题事件

  • 系统已结题 4月4日
  • 已采纳回答 3月27日
  • 创建了问题 3月20日

悬赏问题

  • ¥20 keepalive配置业务服务双机单活的方法。业务服务一定是要双机单活的方式
  • ¥50 关于多次提交POST数据后,无法获取到POST数据参数的问题
  • ¥15 win10,这种情况怎么办
  • ¥15 如何在配置使用Prettier的VSCode中通过Better Align插件来对齐等式?(相关搜索:格式化)
  • ¥100 在连接内网VPN时,如何同时保持互联网连接
  • ¥15 MATLAB中使用parfor,矩阵Removal的有效索引在parfor循环中受限制
  • ¥20 Win 10 LTSC 1809版本如何无损提升到20H1版本
  • ¥50 win10 LTSC 虚拟键盘不弹出
  • ¥30 微信小程序请求失败,网页能正常带锁访问
  • ¥15 Matlab求解微分方程,如何用fish2d进行预优?