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
Explain how a centralized SPC organization works under load sharing operation. Under load sharing operation, an incoming call is allocated randomly or in a predetermined sequen

In an ASP.NET web application that does not build use of routing, an incoming browser request should map to a physical file. If the file does not exist, we get page not found error

Q. SPMD model for programming? A normal assumption was that it must be possible and not too hard to capture the SPMD model for programming MIMD computers in data parallel langu

Write a function "plot2fnhand" that will receive 2 function handles as input arguments, and will show in two Figure Windows plots of these functions, with the function names in the

Q. Explain the Instruction Decode? Instruction Decode: This phase is performed under control of Control Unit of computer. The Control Unit determines the operation which is t


find the radius of curvature at the point (3,3) at a point x3+xy2-6y2=0?

What is a Priority Interrupt? A priority interrupt is an interrupt that establishes a priority over the various sources to determine which condition is to be serviced first whe

Give the organization of centralized store program control ( SPC). Within stored program control systems, a program or set of instructions for the computer that is stored in

A part of an aircraft engine can be given a test before installation.  The test has a 75% chance of revealing a defect if it is present, and the same chance of passing a sound part