Translate assembly language program to machine , Computer Engineering

A useful exercise in understanding assembly language and its relation to machine language is to take a short assembly language program and translate it to machine language by hand.

The following program, countbits, counts the number of bits set to 1 in registers $4 and returns the result in register $6.

main: li $10, 32 # set up loop counter

li $6, 0 # clear output sum

main10: andi $12, $11, 1 # test current bit

beq $12, $0, main20 # skip count if not set

addi $6, $6, 1 # otherwise increment count

main20: srl $11, $11, 1 # shift input right

addi $10, $10, -1 # decrement count

bne $10, $0, main10 # continue until zero

li $2, 10 # Halt code

syscall

Translate this program to machine code by hand, explaining for each line how you worked out the machine instruction.

Although it might be tempting to simply let the SPIM assembler do this, the exercise is useful way of learning the MIPS instruction formats. Refer to Appendix B (Assemblers, Linkers and the SPIM simulator) of the text (4th Edition ) for descriptions of MIPS assembly language instructions and the corresponding machine codes.

Posted Date: 3/1/2013 12:54:03 AM | Location : United States







Related Discussions:- Translate assembly language program to machine , Assignment Help, Ask Question on Translate assembly language program to machine , Get Answer, Expert's Help, Translate assembly language program to machine Discussions

Write discussion on Translate assembly language program to machine
Your posts are moderated
Related Questions
Q. Write a program to perform multiplication of two numbers in specified radix. Check that entered numbers are in specified radix or not else error message should be displayed.

Can I use a Verilog function to define the width of a multi-bit port, wire, or reg type? Width  elements  of  ports,  wire  or  reg  declarations  require  a  constant  in  bot

What do you understand by WWW? WWW (World Wide Web): It is an architectural framework for accessing linked documents outspread over thousands of machines the whole world.

What do you mean by term procedure? Differentiate between far call and near call? PROC: PROC and ENDP directives indicate the start and end of a procedure. These directives for

Why address bus is unidirectional and data bus is bidirectional? Ans) Because there is no require address transaction among processor and peripheral device but data bus is req

Why is the data bus in most microprocessors bidirectional while the address bus is unidirectional?  Data Bus:  These lines are used to send data to memory by output ports and

Define the node of object oriented modeling A node is a physical element which exists at runtime and represents a computational resource usually having a large memory and often

a ship is loaded with a stock of 3 items each unit of item n has a wt wn and vn the max cargo wt the ship can take is the details of 3items are item(n):1 2 3 wt(wn):2 3 1 value(vn)

Explain about the MINI COMPUTER Minicomputers are much smaller in size than mainframe computers and they are also less expensive.  The cost of these computers can differ from a

Why is XML superior to other forms of data exchange? The XML gives universal data format for integrated electronic business solutions. Other database systems and Relational dat