Convert this C++ program exactly as you see it into x86 assembly language:
// Use the Irvine library for the print function
#include <iostream>
// The string that needs to be printed
char word[] = "Golf\0";
// Pointer to a specific character in the string
char * character = word;
//NOTE: This main() function is not portable outside of Visual Studio
void main()
{
// Set up a LOOP - See the while loop's conditional expression below
int ecx = 4;
do
{
// Print the character
// In x86 assembly language you must use the following two lines of code:
// mov al, WHATEVER_CHARACTER_YOU_WANT_TO_PRINT
// call WriteChar
std::cout << *character;
// Increment the pointer
++character;
} while (--ecx != 0);
// In x86 assembly language you must use the following line of code:
// call CrLf
std::cout << std::endl;
// In x86 assembly language you must use the following line of code:
// call WaitMsg system("PAUSE");
}
Here is the conversion of the C program into X86 assembly language
std::ostream::operator<<(std::ostream& (*)(std::ostream&))@plt:
jmp QWORD PTR [rip+0x2fd2] # 404028 <std::ostream::operator<<(std::ostream& (*)(std::ostream&))@GLIBCXX_3.4>
push 0x2
jmp 401020 <.plt>
jmp QWORD PTR [rip+0x2fca] # 404030 <std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char)@GLIBCXX_3.4>
push 0x3
jmp 401020 <.plt>
std::ios_base::Init::Init()@plt:
jmp QWORD PTR [rip+0x2fc2] # 404038 <std::ios_base::Init::Init()@GLIBCXX_3.4>
push 0x4
jmp 401020 <.plt>
std::ios_base::Init::~Init()@plt:
jmp QWORD PTR [rip+0x2fba] # 404040 <std::ios_base::Init::~Init()@GLIBCXX_3.4>
push 0x5
jmp 401020 <.plt>
main:
push rbp
mov rbp,rsp
sub rsp,0x10
mov DWORD PTR [rbp-0x4],0x4
mov rax,QWORD PTR [rip+0x2ed8] # 404060 <character>
movzx eax,BYTE PTR [rax]
movsx eax,al
mov esi,eax
mov edi,0x404080
call 401060 <std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char)@plt>
mov rax,QWORD PTR [rip+0x2ebf] # 404060 <character>
add rax,0x1
mov QWORD PTR [rip+0x2eb4],rax # 404060 <character>
sub DWORD PTR [rbp-0x4],0x1
cmp DWORD PTR [rbp-0x4],0x0
setne al
test al,al
je 4011bd <main+0x4b>
jmp 401181 <main+0xf>
mov esi,0x401030
mov edi,0x404080
call 401050 <std::ostream::operator<<(std::ostream& (*)(std::ostream&))@plt>
mov eax,0x0
leave
ret
_GLOBAL__sub_I_word:
push rbp
mov rbp,rsp
mov esi,0xffff
mov edi,0x1
call 4011d3 <__static_initialization_and_destruction_0(int, int)>
pop rbp
ret
nop WORD PTR cs:[rax+rax*1+0x0]
The output of the code is Golf
For any queries please comment
Get Answers For Free
Most questions answered within 1 hours.