Question

MIPS

1.  Write an input-output utility io_lib.asm that contains the following subprograms:

     a.  input_sub:  get user input

          - prompt the user to enter an integer

          - print the entered input as hexadecimal in the format of:  0xnnnnnnnn

 

     b.  output_sub:  print output

          - print a text string provided by the caller

          - print the value in hexadecimal format

 

2.  Write a logic operation utility logic_lib.asm that contains the following subprograms:

     a.  nor_sub:  take two input parameters, and return the NOR operation on those two parameter.

     b. nand_sub:  take two input parameters, and return the NAND operation on those two parameter.

     c. not_sub:  take one input parameters, and return the NOT operation on that parameter.

     d. mult4_sub:  take an input parameter, and return that parameter multiplied by 4 using only shift and add operations.

     e. mult10_sub:  take an input parameter, and return that parameter multiplied by 10 using only shift and add operations.

     f. cir_sh_r_sub:  take an input parameter as value to shift and a second parameter as the shift amount, and return the shifted value     

     g. cir_sh_l_sub:  take an input parameter as value to shift and a second parameter as shift amount, and return the shifted value

 

3.  Write the main program that does the followings by calling supprograms in io_lib.asm and logic_lib.asm:

 

     a.  Prompt user for 2 input integers:  A and B

 

     b.  Display A and B in hexadecimal format

 

     c.  Display A NOR B

 

     d.  Display A NAND B

 

     e.  Display NOT(A)

 

     f.  Display (A*4) and (B*10)

 

     f.   Show A Right Circular Shift by entered number of bits

 

    g.  Show B Left Circular Shift by entered number of bits

 

 

Sample output:

 

Enter value for A:  5

Hex value of 5 is:  0x05

Enter shift amount for A:  3

 

Enter value for B:  8

Hex value of 8 is:  0x08

Enter shift amount for B:  4

 

A NOR B = 0xFFFFFFF2

A NAND B = 0xFFFFFFF

NOT(A) = 0xFFFFFFFA

A * 4 = 20

B * 10 = 80

 

A circular shifted R by 3 = 0xA0000000

B circular shifted L by 4 = 0x00000080


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

1.Write an input-output utility io_lib.asm that contains the following:


# Read integer A from user and store it into a register

# Display the integer in binary

# Display the integer in Hex

# set Register $a0 to contain only bits 12,13,14,15 of $a0

# Display the integer in binary contained in $a0

# Display the integer in hex contained in $a0


.data

userInput: .asciiz "Please enter your integer: "

binaryInput: .asciiz "Here is the input in binary: "

nl: .asciiz "\n"

hexInput: .asciiz "Here is the input in hexadecimal: "

binaryOutput: .asciiz "Here is the output in binary: "

hexOutput: .asciiz "Here is the output in hexadecimal: "

hexDigit: .asciiz "0123456789ABCDEF"

obuf: .space 100

obufe:


.text

.globl main

main:

# ask end-user to submit an integer value

li $v0,4

la $a0,userInput

syscall


# read user-input

li $v0,5

syscall

move $s0,$v0


# output original in binary

la $a0,binaryInput

li $a1,32

jal prtbin


# output original in hex

la $a0,hexInput

li $a1,32

jal prthex


# isolate bits 12,13,14,15

srl $s0,$s0,12

andi $s0,$s0,0x0F


# output isolated in binary

la $a0,binaryOutput

li $a1,4

jal prtbin


# output isolated in hex

la $a0,hexOutput

li $a1,4

jal prthex


# exit the program

li $v0,10

syscall


# prtbin -- print in binary

#

# arguments:

# a0 -- output string

# a1 -- number of bits to output

prtbin:

li $a2,1 # bit width of number base digit

j prtany


# prthex -- print in binary

#

# arguments:

# a0 -- output string

# a1 -- number of bits to output

prthex:

li $a2,4 # bit width of number base digit

j prtany


# prtany -- print in given number base

#

# arguments:

# a0 -- output string

# a1 -- number of bits to output

# a2 -- bit width of number base digit

# s0 -- number to print

#

# registers:

# t0 -- current digit value

# t5 -- current remaining number value

# t6 -- output pointer

# t7 -- mask for digit

prtany:

li $t7,1

sllv $t7,$t7,$a2 # get mask + 1

subu $t7,$t7,1 # get mask for digit


la $t6,obufe # point one past end of buffer

subu $t6,$t6,1 # point to last char in buffer

sb $zero,0($t6) # store string EOS


move $t5,$s0 # get number


prtany_loop:

and $t0,$t5,$t7 # isolate digit

lb $t0,hexDigit($t0) # get ascii digit


subu $t6,$t6,1 # move output pointer one left

sb $t0,0($t6) # store into output buffer


srlv $t5,$t5,$a2 # slide next number digit into lower bits

sub $a1,$a1,$a2 # bump down remaining bit count

bgtz $a1,prtany_loop # more to do? if yes, loop


# output string

li $v0,4

syscall


# output the number

move $a0,$t6 # point to ascii digit string start

syscall


# output newline

la $a0,nl

syscall


jr $ra # return

answered by: codegates
Add a comment
Know the answer?
Add Answer to:
MIPS
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
  • MIPS Assembly

    Write a logic operation utility logic_lib.asm that contains the following subprograms:a. nor_sub: take two input parameters, and return the NOR operation on those two parameter.b. nand_sub: take two input parameters, and return the NAND operation on those two parameter.c. not_sub: take one input parameters, and return the NOT operation on that parameter.d. mult4_sub: take an input parameter, and return that parameter multiplied by 4 using only shift and add operations.e. mult10_sub: take an input parameter, and return that parameter multiplied...

  • [Using Python] I need my code given below to loop the user input, so that you...

    [Using Python] I need my code given below to loop the user input, so that you are asked to input without it stopping after 4 inputs. Code: #A program that converts a hexadecimal number to its decimal value #Define function for hexadecimal to decimal def hexToDec(hexi): result = 0 #For loop to test input for correct values for char in hexi: if 'A' <= char <= 'F' or 'a' <= char <= 'f': if 'a' <= char <= 'f': result...

  • PRG255 3.2 (2 marks) Write a C program that uses the bitwise shift operators to shut...

    PRG255 3.2 (2 marks) Write a C program that uses the bitwise shift operators to shut the The program will ask the user to enter an unsigned also how many bits for the shift operation. Display the entered operation in both decimal and binary formats, vise shirt operators to shift the bits to the right >> or the left << user to enter an unsigned integer number, choose right shift or left shift, and orauon. Display the entered number and...

  • JUST GIVE ME THE C CODE FOR THIS QUESTION. I GOT THE ASSEMBLY CODE.

    JUST GIVE ME THE C CODE FOR THIS QUESTION. I GOT THE ASSEMBLY CODE. In this assignment, you will create a C program that iteratively populates a fixed-size integer array of 3 elements, array α.withhexadecimal integer valuesprovided by scanf. The user will enter 3 positive hexadecimal integer values, one per line, and the program will store the 3 values in arYay _afOJ,arvay aflJ, and crr ay_af2J. Once the 3 integers are entered, your program will print the array ain 32...

  • For this problem you will design a circular bit shifter in VHDL. These circuits are especially...

    For this problem you will design a circular bit shifter in VHDL. These circuits are especially useful for aligning signals in communications equipment. Your bit shifter should have a 4-bit input, a 4-bit output, and a 2-bit shift amount. The shift amount will specify how many bits are to be shifted, 0, 1, 2, or 3 bits. To perform a circular shift, take the N least significant bits, and put them in the most significant position. For example, 1010 shifted...

  • Summary: Write a C program that prompts the user to enter 2 positive integer numbers, display...

    Summary: Write a C program that prompts the user to enter 2 positive integer numbers, display the numbers in 3 formats. Then check, whether the larger of the 2 is evenly divisible by the smaller. Detail: Write a complete C program, more complex than the typical "hello world" program. Prompt the user to enter 2 integer numbers that are not negative. After either entry, display that number again. Print the smaller in hexadecimal, in decimal, and in octal format. Include...

  • Write a program that allows the user to enter an unsigned integer (the maximum value of...

    Write a program that allows the user to enter an unsigned integer (the maximum value of an unsigned 4-byte int is 232 = 4,294,967,296) and reverses its format (from little to big endian, or vice versa). Print out the user-entered number in hexadecimal and binary, reverse the endianness, and print the reverse in hexadecimal and binary. Integers in most machine architectures are represented in little endian format: the least significant byte is stored in the smallest address; for instance, the...

  • Write a program that implements an elementary bit stream cipher. An elementary level bit stream cipher...

    Write a program that implements an elementary bit stream cipher. An elementary level bit stream cipher is an encryption algorithm that encrypts 1 byte of plain text at a time. This one uses a given 4-bit bit pattern as the key. The size of the encrypted message that we want to be able to send has a maximum length of 200 characters. You must: 1. prompt the user to input the clear text to be encrypted. You must use printf()...

  • Assembly language 64 bit please ! An example file for set up ==========+ ;| Data Segment...

    Assembly language 64 bit please ! An example file for set up ==========+ ;| Data Segment BEGINS Here | ;+======================================================================+ segment .data ;Code this expression: sum = num1+num2 num1 dq 0 ;left operand of the addition operation num2 dq 0 ;right operand of the addition operation sum dq 0 ;will hold the computed Sum value RetVal dq 0 ;Integer value RETURNED by function calls ;can be ignored or used as determined by the programmer ;Message string prompting for the keyboard...

  • CNIT 105 In Lab10 Due: By the end of your lab session OBJECTIVES: bitwise operations main...

    CNIT 105 In Lab10 Due: By the end of your lab session OBJECTIVES: bitwise operations main () function: 1. Declare an int variable, name it number. 2. Prompt the user to enter a whole number- read it into the variable. Validate the range in a loop. Valid range is 20 to 200 both inclusive . 3. Display the number to the screen (base 10) 4, Display the number in hexadecimal (Use %X) 5. Display number to the screen -It will...

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