Question

In: Computer Science

How would you go about creating a subroutine in MARIE assembly language that swaps contents between...

How would you go about creating a subroutine in MARIE assembly language that swaps contents between two memory locations? In this instance the contents for each memory location are names

Solutions

Expert Solution

WE ARE DOING COPY CONTENTS OF FIRST LOCATION AND STORE INTO THIRD LOCATION THEN AGAIN COPY CONTENT OF SECOND LOCATION INTO FIRST AND THEN THIRD TO SECOND,

THIS IS THE WAY WE ARE GOING TO SWAP THE CONTENTS.

CLEAR

  STORE INDEX

WHILE, LOAD STR1_BASE //THROUGH THIS LOOP WE ARE COPYING CONTENT OF FIRST LOCATION

ADD INDEX INTO THIRD LOCATION.

STORE ADDR // FIRST LOAD THE ADDRESS OF FIRST STRING AND THEN ADD OFFSET

CLEAR AND INTO ANOTHER LOCATION ADDR.

LOAD TEMP_BASE //THIS IS OUR THIRD LOCATION

ADD INDEX

STORE ADDR2

CLEAR

ADDI ADDR .// FETCH VALUE AT ADDRESS ADDR .

STORE ADDR2

SKIPCOND 400 // SKIP IF CHAR IS NULL

JUMP DO

JUMP NEXT

DO, LOAD INDEX

ADD ONE // INCREMENT OFFSET

STORE INDEX

JUMP WHILE

NEXT CLEAR

LOAD ZERO

STORE INDEX

WHILE2, LOAD STR2_BASE //SIMILARLY WE WILL DO FOR SECOND LOCATION

ADD INDEX

STORE ADDR

CLEAR

LOAD STR1_BASE

ADD INDEX

STORE ADDR2

CLEAR

ADDI ADDR

STORE ADDR2

SKIPCOND 400

JUMP LOOP2

JUMP AGAIN

LOOP2, LOAD INDEX

ADD ONE

STORE INDEX

JUMP WHILE2

AGAIN, CLEAR

LOAD ZERO

STORE INDEX

CLEAR

WHILE3, LOAD TEMP_BASE

ADD INDEX

STORE ADDR

CLEAR

LOAD STR2_BASE

ADD INDEX

STORE ADDR2

CLEAR

ADDI ADDR

STORE ADDR2

SKIPCOND 400

JUMP LOOP3

JUMP END

LOOP3, LOAD INDEX

ADD ONE

STORE INDEX

JUMP WHILE3

END, HALT


Related Solutions

Write a parity checker for the ASCII system in MARIE. MARIE is an assembly language. The...
Write a parity checker for the ASCII system in MARIE. MARIE is an assembly language. The parity checker should repeatedly execute a loop that performs the following tasks: 1. Ask the user for an input X, which can be any printable ASCII character from Table 1; 2. Output the decimal code of X; 3. Output the total number of 1’s that appears in the binary code of X; 4. Output the parity bit which, when added to the binary code...
1. How to create a newline subroutine in micro assembly language that sends the CR and...
1. How to create a newline subroutine in micro assembly language that sends the CR and LF codes to putchUSART0 (write down the full code in micro assembly language). Terminal programs move the cursor to the beginning of a line with a Carriage Return (CR) code 0x0D and down a line with the Line Feed (LF) code 0x0A.
How would you go about creating a linear regression model to predict the 2020 Presidential Election?
How would you go about creating a linear regression model to predict the 2020 Presidential Election?
Write an MSP430 assembly language program that implements the following algorithm: a subroutine, called 'numadd' that...
Write an MSP430 assembly language program that implements the following algorithm: a subroutine, called 'numadd' that sums up all the numeric characters present in a phrase ("string" that follows the "C" language convention). By For example, if the phrase is "Today is the 28th of month 9", the subroutine must perform the following sum: 2 + 8 + 9 = 19. The subroutine must receive the address of the first character of the corresponding phrase in the "stack", and return...
Write an MSP430 assembly language program that implements the following algorithm: a subroutine, called ‘numadd’ that...
Write an MSP430 assembly language program that implements the following algorithm: a subroutine, called ‘numadd’ that sums up all the numeric characters present in a sentence (“string” that follows the “C” language convention). For example, if the phrase is "Today is the 21st of month 5", the subroutine must perform the following sum: 2 + 1 + 5 = 8. The subroutine must receive the address of the first character of the corresponding phrase in the " stack ”, and...
Assembly Language Define a 64-bit constant signed integer in Flash. Then, Write a subroutine count_1s that...
Assembly Language Define a 64-bit constant signed integer in Flash. Then, Write a subroutine count_1s that would count the number of 1s in a byte. The subroutine will receive the input parameter in A and return the result back in A. Use this subroutine to write a program that would count the number of 1s inside the 64-bit constant signed integer. Define a variable that would hold the total count of 1s. (Application of Shift/Rotate instructions) (No specific Architecture)
Using the MARIE computer assembly language, write a program that computes the following expression: z =...
Using the MARIE computer assembly language, write a program that computes the following expression: z = a * b * c. The computer will read in the input values a, b, and c from the keyboard and the final result (z) have to be displayed. In addition, every time an input value is read in, it must be displayed on the screen. Remember that the instruction set does not have an instruction to execute multiplication. Note: If any of the...
Understanding Assembly Language. For each problem, show the contents or setting of the requested items after...
Understanding Assembly Language. For each problem, show the contents or setting of the requested items after executing the instructions. mov eax, 0FFFFFBFDh ; i.e., -1027 mov ebx, -16        ; i.e., FFFFFFF0h mov edx, 0 idiv bl Show the hexadecimal digits in eax:_______________ Show the hexadecimal digits in edx:_______________ mov eax, 0FFFFFBFDh ; i.e., -1027 mov ebx, -16        ; i.e., FFFFFFF0h mov edx, 0 cwd idiv bx Show the hexadecimal digits in eax:_______________ Show the hexadecimal digits in edx:_______________ mov eax,...
Imagine you are a leader in a private security company. What is your ethical code? How would you go about creating an ethical code?
Imagine you are a leader in a private security company. What is your ethical code? How would you go about creating an ethical code?
In YASM Assembly language, how would you convert a hex byte into it's ascii representation?
In YASM Assembly language, how would you convert a hex byte into it's ascii representation?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT