Question 2 Transform the following “C” program into assembly for the 6808 Microc
ID: 3776087 • Letter: Q
Question
Question 2
Transform the following “C” program into assembly for the 6808 Microcontroller.
• Remember when converting this “C” code to follow best practices covered in DEF in terms of implementing subroutines in assembly
o This means that parameters are passed on the stack to subroutines
o Return values are passed back on the stack
o You clean up the stack after every use (every subroutine call) to prepare it for the next call
Keep in mind that once your translated this program into assembly – you can step through it to ensure that it behaves correctly and calculates the expected results.
/* -------------------------------------------------------------
PURPOSE: This program will take 2 operand values and
calculate the sum and difference of the values
------------------------------------------------------------- */
// This function calculates the sum of 2 operands called "A" and "B"
Int calculateSum(int A, int B)
{
return (A + B);
}
// This function calculates the difference between 2 operands by negating B and adding it to A
int calculateDifference(int A, int B)
{
return (calculateSum(A, -B)); // reuse the calculateSum function
}
void main(void)
{
int firstOperand = 18; // to be stored at address $80 within the 6808
int secondOperand = 8; // to be stored at address $81 within the 6808
int sum = 0; // to be stored at address $84 within the 6808
int difference = 0; // to be stored at address $86 within the 6808
// call the calculateSum function in order to calculate the total and store it in the "sum" variable
sum = calculateSum(firstOperand, secondOperand);
// call the calculateDifference function in order to calculate the difference and store it in the "difference" variable
difference = calculateDifference(firstOperand, secondOperand);
}
please comment on each line
Explanation / Answer
.Ltext0: .globl calculateSum calculateSum: .LFB0: .cfi_startproc 0000 55 pushq %rbp .cfi_def_cfa_offset 16 .cfi_offset 6, -16 0001 4889E5 movq %rsp, %rbp .cfi_def_cfa_register 6 0004 897DFC movl %edi, -4(%rbp) 0007 8975F8 movl %esi, -8(%rbp) 000a 8B55FC movl -4(%rbp), %edx 000d 8B45F8 movl -8(%rbp), %eax 0010 01D0 addl %edx, %eax 0012 5D popq %rbp .cfi_def_cfa 7, 8 0013 C3 ret .cfi_endproc .LFE0: .globl calculateDifference calculateDifference: .LFB1: .cfi_startproc 0014 55 pushq %rbp .cfi_def_cfa_offset 16 .cfi_offset 6, -16 0015 4889E5 movq %rsp, %rbp .cfi_def_cfa_register 6 0018 4883EC08 subq $8, %rsp 001c 897DFC movl %edi, -4(%rbp) 001f 8975F8 movl %esi, -8(%rbp) 0022 8B45F8 movl -8(%rbp), %eax 0025 F7D8 negl %eax 0027 89C2 movl %eax, %edx 0029 8B45FC movl -4(%rbp), %eax 002c 89D6 movl %edx, %esi 002e 89C7 movl %eax, %edi 0030 E8000000 call calculateSum 00 0035 C9 leave .cfi_def_cfa 7, 8 0036 C3 ret .cfi_endproc .LFE1: .globl main main: .LFB2: .cfi_startproc 0037 55 pushq %rbp .cfi_def_cfa_offset 16 .cfi_offset 6, -16 0038 4889E5 movq %rsp, %rbp .cfi_def_cfa_register 6 003b 4883EC10 subq $16, %rsp 003f C745F012 movl $18, -16(%rbp) 000000 0046 C745F408 movl $8, -12(%rbp) 000000 004d C745F800 movl $0, -8(%rbp) 000000 0054 C745FC00 movl $0, -4(%rbp) 000000 005b 8B55F4 movl -12(%rbp), %edx 005e 8B45F0 movl -16(%rbp), %eax 0061 89D6 movl %edx, %esi 0063 89C7 movl %eax, %edi 0065 E8000000 call calculateSum 00 006a 8945F8 movl %eax, -8(%rbp) 006d 8B55F4 movl -12(%rbp), %edx 0070 8B45F0 movl -16(%rbp), %eax 0073 89D6 movl %edx, %esi 0075 89C7 movl %eax, %edi 0077 E8000000 call calculateDifference 00 007c 8945FC movl %eax, -4(%rbp) 007f 90 nop 0080 C9 leave .cfi_def_cfa 7, 8 0081 C3 ret .cfi_endproc .LFE2: .Letext0:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.