In this program you are to simulate a 2-pass assembler in C++. The input to this
ID: 3718344 • Letter: I
Question
In this program you are to simulate a 2-pass assembler in C++. The input to this program is an assembly language program (see the handout on SMC 68000) and the output should include a symbol table and the machine code version of the input. You have to echo the input. Do file I/O You are implementing two classical algorithms (Fig. 6.1 & Fig 6.2) INPUT ORG MOVE #79, $00002000 TRAP #1 MOVEDO, S00002004STORE DO IN LOCATION Y MOVE S00002000, DO FETCH VARIABLE I FOR THE AD ADD MOVE DO, S00002002 ADDI #18,$00002002 ADD 18 TOX TRAP #2 TRAP END S00000500 READLN (Y), INPUT INTO DO LOOP1 S00002004, DOADD Y+ STORE THE SUM IN X LOOP2 PRINTX STOP #0 OUTPUT Address 00000500 33FC Machine code Operands Instructions 4F MOVE #79, $00002000 SYMBOL TABLE LABEL 1 ADDRESS LABEL 2 ADDRESSExplanation / Answer
ANSWER
GIVEB BY
SourceCode:
.LC0:
.string "Enter a positive integer: "
.LC1:
.string "Sum = "
main:
push rbp
mov rbp, rsp
sub rsp, 16
mov DWORD PTR [rbp-4], 0
mov esi, OFFSET FLAT:.LC0
mov edi, OFFSET FLAT:std::cout
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*)
lea rax, [rbp-12]
mov rsi, rax
mov edi, OFFSET FLAT:std::cin
call std::basic_istream<char, std::char_traits<char> >::operator>>(int&)
mov DWORD PTR [rbp-8], 1
.L3:
mov eax, DWORD PTR [rbp-12]
cmp DWORD PTR [rbp-8], eax
jg .L2
mov eax, DWORD PTR [rbp-8]
add DWORD PTR [rbp-4], eax
add DWORD PTR [rbp-8], 1
jmp .L3
.L2:
mov esi, OFFSET FLAT:.LC1
mov edi, OFFSET FLAT:std::cout
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 rdx, rax
mov eax, DWORD PTR [rbp-4]
mov esi, eax
mov rdi, rdx
call std::basic_ostream<char, std::char_traits<char> >::operator<<(int)
mov eax, 0
leave
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 .L7
cmp DWORD PTR [rbp-8], 65535
jne .L7
mov edi, OFFSET FLAT:std::__ioinit
call std::ios_base::Init::Init()
mov edx, OFFSET FLAT:__dso_handle
mov esi, OFFSET FLAT:std::__ioinit
mov edi, OFFSET FLAT:std::ios_base::Init::~Init()
call __cxa_atexit
.L7:
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
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.