5 条题解
-
6
【汇编系列题解,看懂了就会写汇编了】
这道题是一道难题,大家需要使用汇编语言进行提交:
首先我们要知道汇编是直接控制计算机硬件进行运算,存储的。
而我们可以先用
C艹
语言写出伪代码:#include <iostream> int main(){ std::cout << "Technoblade Never dies!!!"; }
这时候我们会发现其实
"Technoblade Never dies!!!"
是一个字符常量,所以拆分后得到:#include <iostream> #include <string.h> const string h = "Technoblade Never dies!!!"; int main(){ std::cout << h; }
接下来开始转换为汇编语言:
字符串部分:
#include <string> using namespace std; const string h = "Technoblade Never dies!!!";
转换过来是:
.LC0: .string "basic_string: construction from null is not valid" .LC1: .string "Technoblade Never dies!!!" __static_initialization_and_destruction_0(int, int): push rbp mov rbp, rsp push rbx sub rsp, 40 mov DWORD PTR [rbp-36], edi mov DWORD PTR [rbp-40], esi cmp DWORD PTR [rbp-36], 1 jne .L32 cmp DWORD PTR [rbp-40], 65535 jne .L32 lea rax, [rbp-17] mov rdi, rax call std::allocator<char>::allocator() [complete object constructor] lea rax, [rbp-17] mov rdx, rax mov esi, OFFSET FLAT:.LC1 mov edi, OFFSET FLAT:_ZL1h call std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string<std::allocator<char> >(char const*, std::allocator<char> const&) lea rax, [rbp-17] mov rdi, rax call std::allocator<char>::~allocator() [complete object destructor] mov edx, OFFSET FLAT:__dso_handle mov esi, OFFSET FLAT:_ZL1h mov edi, OFFSET FLAT:_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED1Ev call __cxa_atexit jmp .L32 mov rbx, rax lea rax, [rbp-17] mov rdi, rax call std::allocator<char>::~allocator() [complete object destructor] mov rax, rbx mov rdi, rax call _Unwind_Resume .L32: mov rbx, QWORD PTR [rbp-8] leave ret _GLOBAL__sub_I_example.cpp: push rbp mov rbp, rsp mov esi, 65535 mov edi, 1 call __static_initialization_and_destruction_0(int, int) pop rbp ret
这里是把字符串的std也封装进去了。
接着封装
main
部分:.LC0: .string "" main: push rbp mov rbp, rsp mov esi, OFFSET FLAT:.LC0 mov edi, OFFSET FLAT:_ZSt4cout call std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*) mov eax, 0 pop rbp ret __static_initialization_and_destruction_0(int, int): push rbp mov rbp, rsp sub rsp, 16 mov DWORD PTR [rbp-4], edi mov DWORD PTR [rbp-8], esi cmp DWORD PTR [rbp-4], 1 jne .L5 cmp DWORD PTR [rbp-8], 65535 jne .L5 mov edi, OFFSET FLAT:_ZStL8__ioinit call std::ios_base::Init::Init() [complete object constructor] mov edx, OFFSET FLAT:__dso_handle mov esi, OFFSET FLAT:_ZStL8__ioinit mov edi, OFFSET FLAT:_ZNSt8ios_base4InitD1Ev call __cxa_atexit .L5: nop leave ret _GLOBAL__sub_I_main: push rbp mov rbp, rsp mov esi, 65535 mov edi, 1 call __static_initialization_and_destruction_0(int, int) pop rbp ret
这里是cout的main部分,把字符串h替换为空字符串了。
接着拼接起来:
.LC0: .string "Technoblade Never dies!!!" main: push rbp mov rbp, rsp mov esi, OFFSET FLAT:.LC0 mov edi, OFFSET FLAT:_ZSt4cout call std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*) mov eax, 0 pop rbp ret __static_initialization_and_destruction_0(int, int): push rbp mov rbp, rsp sub rsp, 16 mov DWORD PTR [rbp-4], edi mov DWORD PTR [rbp-8], esi cmp DWORD PTR [rbp-4], 1 jne .L5 cmp DWORD PTR [rbp-8], 65535 jne .L5 mov edi, OFFSET FLAT:_ZStL8__ioinit call std::ios_base::Init::Init() [complete object constructor] mov edx, OFFSET FLAT:__dso_handle mov esi, OFFSET FLAT:_ZStL8__ioinit mov edi, OFFSET FLAT:_ZNSt8ios_base4InitD1Ev call __cxa_atexit .L5: nop leave ret _GLOBAL__sub_I_main: push rbp mov rbp, rsp mov esi, 65535 mov edi, 1 call __static_initialization_and_destruction_0(int, int) pop rbp ret
- 1
信息
- ID
- 2
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- 3
- 标签
- 递交数
- 60
- 已通过
- 32
- 上传者