Question

Write the assembly code that will transform a squared image into a negative print. (HARD-CODED OUTPUT...

Write the assembly code that will transform a squared image into a negative print. (HARD-CODED OUTPUT WILL RESULT IN ZERO.)

That is, every pixel whose unsigned value is 0 should change to 255, 1 should change to 254, 2 should change to 253, ... 255 should change to 0.

$a0 contains the address of the input buffer, $a1 contains the address of the output buffer address, and $a2 contains the image dimension. Look at the below image for your reference:

(Note: You can testify the following in MARS; however, we only evaluate the logic of your program.) (YOU CANNOT ASSUME IT'S A 3X3 IMAGE.)

j main .data input_3x3: .byte 0, 1, 2, 127, 128, 129, 253, 254, 255 output_3x3: .space 9 expected_output_3x3: .byte 255, 254, 253, 128, 127, 126, 2, 1, 0 .text

##################### #a0: input buffer address #a1: output buffer address #a2: image dimension (Image will be square sized, i.e. total size = a2*a2) ##################### image_negative: ############## your code begins here #################

############## your code ends here ################## jr $ra #############################

main: la $a0, input_3x3 la $a1, output_3x3 li $a2, 3 jal image_negative

li $t0, 9 la $t1, output_3x3 print_3x3: lbu $a0, ($t1) li $v0, 1 syscall li $v0, 11 li $a0, 32 syscall addi $t0, $t0, -1 addi $t1, $t1, 1 bnez $t0, print_3x3

_end: #end program li $v0, 10 syscall

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please find the answer below.
Please do comments in case of any issue. Also, don't forget to rate the question. Thank You.

Code.asm

a 2*a 2) 9 #a0: input buffer address 10 #al: output buffer address 11 #a2: image dimension (Image will be square sized, i.e.

.data
input_3x3: .byte 0, 1, 2, 127, 128, 129, 253, 254, 255
output_3x3: .space 9
expected_output_3x3: .byte 255, 254, 253, 128, 127, 126, 2, 1, 0
.text
j main

#####################
#a0: input buffer address
#a1: output buffer address
#a2: image dimension (Image will be square sized, i.e. total size = a2*a2)
#####################
image_negative:

############## your code begins here #################
mul $s0,$a2,$a2 #get number of element in 2d array
li $t0,0 #index
li $s7,255 #load max values
loop:
mul $t1,$t0,1 #get index of i
add $t2,$t1,$a1 #get value of output_3x3[i]
add $t1,$t1,$a0 #get value of input_3x3[i]
lb $t1,($t1) #get value of array[i]
sub $t1,$s7,$t1 #get 255 - current index
sb $t1,($t2) #store data in out
addi $t0,$t0,1
blt $t0,$s0 loop #Loop for all element
############## your code ends here ##################
jr $ra
#############################
main:
la $a0, input_3x3
la $a1, output_3x3
li $a2, 3
jal image_negative
li $t0, 9
la $t1, output_3x3
print_3x3:
lbu $a0, ($t1)
li $v0, 1
syscall
li $v0, 11
li $a0, 32
syscall
addi $t0, $t0, -1
addi $t1, $t1, 1
bnez $t0, print_3x3
_end:
#end program
li $v0, 10
syscall

output

Clear 255 254 253 128 127 126 2 1 0 program is finished running

Add a comment
Know the answer?
Add Answer to:
Write the assembly code that will transform a squared image into a negative print. (HARD-CODED OUTPUT...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • WRITE THE FOLLOWING CODE IN FLOATING POINT NUMBERS IN ASSEMBLY LANGUAGE USING MIPS IN MARS .data...

    WRITE THE FOLLOWING CODE IN FLOATING POINT NUMBERS IN ASSEMBLY LANGUAGE USING MIPS IN MARS .data prompt: .asciiz "\nMaximum number is : " prompt1: .asciiz "\nMinimum number is : " prompt2: .asciiz "\nRange of the array is : " size: .word 10 #load array array: .word 23, -12, 45, -32, 52, -72, 8, 13,22,876 .text #load address of array and size la $s4,array #load address of A lw $t0,size #load i to t0 jal getArrayRange li $v0, 4    la...

  • MIPS Insertion program.........I could really use some help ASAP

    I have this MIPS program and I'm having trouble with it. This program is user inputs numbers until zero and sorts and print the numbers in order. Please soove this issue. You can use any sorting algorithm except bubble sort.  Need it as soon as possible. Here is the code:.datanum: .word 0space: .byte ' ' .text main:  # la $t0, val # loads val into a register  # li $t1, 0      #keeps track of how many numbers entered  la $a0,...

  • what is the output of the following assembly code ? .data A: .word 84 111 116 97 108 32 105 115 32 . text main:​li $v0, 1l ​li $s0,0 ​la $s1, A ​li $t3, 0 loop: ​slti $t0, $s0, 17   ​be...

    what is the output of the following assembly code ? .data A: .word 84 111 116 97 108 32 105 115 32 . text main:​li $v0, 1l ​li $s0,0 ​la $s1, A ​li $t3, 0 loop: ​slti $t0, $s0, 17   ​beq: $t0, $zero, end ​sll $t1, $s0 2 ​add $t2 $s1 $t1   ​syscall ​addi $s0, $s0, 1 ​j loop end: ​li $v0, 1 ​add $a0, $zero, $t3 ​syscall

  • The code below generates 10 random lowercase characters a – z and stores the characters in...

    The code below generates 10 random lowercase characters a – z and stores the characters in memory. Expand this code to CAPITALIZE all the characters in memory. Your code should iterate all characters in memory and change their value to their uppercase equivalent. For instance, character ‘a’ would become ‘A and ‘z’ would become ‘Z’.    Hint: The ASCII table on the backside of this sheet will be necessary in answering this question. li $t0, 0 # i= 0 move $s0,...

  • im trying to complete mips program code about a calculator program that can calculate integer addition...

    im trying to complete mips program code about a calculator program that can calculate integer addition / subtraction written using the MIPS assembler. im having hard times to debug this. The input is given to the array of Formula char (base address $ s0) in the form of a formula. The null character (\ 0, ASCII code 0) is placed at the end. The calculation result is given to the register $ s1 and the overflow is ignored. For example,...

  • Create a program that performs the following operations: 1. Prompt for and accept a string of...

    Create a program that performs the following operations: 1. Prompt for and accept a string of up to 80 characters from the user. • The memory buffer for this string is created by: buffer: .space 80 #create space for string input The syscall to place input into the buffer looks like: li $v0,8 # code for syscall read_string la $a0, buffer #tell syscall where the buffer is li $a1, 80 # tell syscall how big the buffer is syscall 2....

  • Subroutines in MIPS Determines the minimum of two integers Functions within the MIPS slides describe how...

    Subroutines in MIPS Determines the minimum of two integers Functions within the MIPS slides describe how one can use subroutines (also called procedures, functions, and methods) in MIPS. Because of the importance of subroutines in modern programming, most hardware designers include mechanisms to help programmers. In a high-level language like C or Java, most of the details of subroutine calling are hidden from the programmer. MIPS has special registers to send information to and from a subroutine. The registers $a0,...

  • Complete count_bits function. You are given an 32-bits integer stored in $t0. Count the number of...

    Complete count_bits function. You are given an 32-bits integer stored in $t0. Count the number of 1's in the given number. For example: 1111 0000 should return 4 j main ############################################################### # Data Section .data # new_line: .asciiz "\n" space: .asciiz " " double_range_lbl: .asciiz "\nDouble range (Decimal Values) \nExpected output:\n1200 -690 104\nObtained output:\n" swap_bits_lbl: .asciiz "\nSwap bits (Hexadecimal Values)\nExpected output:\n75757575 FD5775DF 064B9A83\nObtained output:\n" count_bits_lbl: .asciiz "\nCount bits \nExpected output:\n20 24 13\nObtained output:\n" swap_bits_test_data: .word 0xBABABABA, 0xFEABBAEF, 0x09876543 swap_bits_expected_data: .word...

  • Assignment 4 File “quad_sol.s” contains a quadratic polynomial solver, which calculates the integer solution of a quadratic polynomial equation. 1. Rewrite the program using instructions reordering to...

    Assignment 4 File “quad_sol.s” contains a quadratic polynomial solver, which calculates the integer solution of a quadratic polynomial equation. 1. Rewrite the program using instructions reordering to reduce the number of cycles needed to execute the program. Indicate the number of cycle reduction. 2. Describe how forwarding would affect the execution of the program. CODE # quad_sol.s # This assembly program calculates the integer solutions of a quadratic polynomial. # Inputs : The coefficients a,b,c of the equation a*x^2 +...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT