Question

In: Computer Science

uestion 2 Transform the following “C” program into assembly for the 6808 Microcontroller.  Remember when...

uestion 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"

}

please help I need the code in assembly

Solutions

Expert Solution

.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 Solutions

Write an assembly language program for 8051 microcontroller to find the sum of the following series,...
Write an assembly language program for 8051 microcontroller to find the sum of the following series, 1, -2, +3, -4, +5, -6,..., up to 100 terms. Store lower byte in R0 and higher byte in R1.
write a program for the microcontroller-msp430fr6989 using code composer studio not assembly language. write a code...
write a program for the microcontroller-msp430fr6989 using code composer studio not assembly language. write a code that transmits a single character and lights the red LED upon receiving that character. The board will "talk" to itself. The green LED should turn on whenever a message is sent and the LCD will display the message being received.
Assembly Language Programming Construct an assembly language program fragment equivalent to the following C/C++ statement: if...
Assembly Language Programming Construct an assembly language program fragment equivalent to the following C/C++ statement: if (M <= N + 3 && (C == ‘N’ || C == ‘n’)) C = ‘0’; else C = ‘1’; Assume that M and N are 32-bit signed integer variables, and C is an 8-bit ASCII character variable. All variables are stored in memory, and all general-purpose registers are available for use.
(MUST BE DONE IN C (NOT C++)) For this program, remember to use feet and inches....
(MUST BE DONE IN C (NOT C++)) For this program, remember to use feet and inches. First, ask the user for the name of students they have in their class. Then, using a loop, you will ask for each student’s height. However, you will have to use two separate variables, one for feet and one for inches. Then, you will have to call two functions. The first function will check if the values entered are valid (check if number of...
1. An LED is connected to PORTB.5 of ATmega328 microcontroller. Write a C Program that toggles...
1. An LED is connected to PORTB.5 of ATmega328 microcontroller. Write a C Program that toggles LED after 0.5 Seconds. Assume XTAL = 16MHz. To generate this delay use Timer 1 CTC (Clear Timer on Compare match) mode Programming. 2. Write a program to generate a square wave of frequency of 250 Hz with 50% duty cycle on PORTB.5. Assume XTAL = 16MHz. Use Timer 2 Normal Mode Programming. 3. Write a program using 16-bit timer to generate a square...
Remember we're only using C to program this. That does not mean C++, just no! This...
Remember we're only using C to program this. That does not mean C++, just no! This one's long so pay attention. You are going to create a structure that resembles a university’s profile (Any university name is ok, just pick one). This structure must contain 5 members. They are listed here: 1. One member for number of undergraduate students 2. One member for number of graduate students 3. One member for number of classrooms 4. One member for the name...
C# CODE C# 1) Write a program that calculates a student's GPA. Remember, an A is...
C# CODE C# 1) Write a program that calculates a student's GPA. Remember, an A is worth 4 points, a B is worth 3 points, a C is worth 2 points, a D is worth 1 point, and an F is worth 0 points. For the purposes of this assignment, assume that all classes carry the same number of credit hours. 2) Use a sentinel-controlled loop to gather a variable number of letter grades. This should terminate the loop if...
Write an assembly language program that corresponds to the following C program ****Please give correct answer...
Write an assembly language program that corresponds to the following C program ****Please give correct answer using Pep/9 machine**** int num1; int num2; ;int main () { scanf("%d", &num1); num2 = -num1; printf("num1 = %d\n", num1); printf("num2 = %d\n", num2); return 0; }
Write the LEGv8 assembly program for following c program. Assume array1, array2 and array3 are stored...
Write the LEGv8 assembly program for following c program. Assume array1, array2 and array3 are stored in memory with base addresses at 1000, 2000 and 3000 respectively. int absoluteDifference(int x, int y) { int r; if (x > y) r = x - y; else r = y - x; return r; } int main() { for (int i=0; i < 10; i++) { int a = array1[i]; int b = array2[i]; int c = absoluteDifference(a, b); array3[i] = c;...
Write the LEGv8 assembly program for following c program. Assume array1, array2 and array3 are stored...
Write the LEGv8 assembly program for following c program. Assume array1, array2 and array3 are stored in memory with base addresses at 1000, 2000 and 3000 respectively. int absoluteDifference(int x, int y) { int r; if (x > y) r = x - y; else r = y - x; return r; } int main() { for (int i=0; i < 10; i++) { int a = array1[i]; int b = array2[i]; int c = absoluteDifference(a, b); array3[i] = c;...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT