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
SubProgram or Procedure Level This level consists of subroutines, procedures or subprograms. Average grain size is used at this level containing various thousands of instructio

An expert system has death that is it operate effectively in a narrow domain containing difficult challenging problems. Thus the rules in an experts systems are necessarily co

Elucidate in brief the functions of the clock generator chip, 8284. 8284 Clock generator: 8284 is an ancillary component to the microprocessors. Without clock generator, many

INSERT OPERATION The insert operation inserts a new value into a set of bits. This is done by first masking bits and then O ring them with required value. For illustration, sup

XML is the Extensible Markup Language. It betters the functionality of the Web by letting you recognize your information in a more accurate, flexible, and adaptable way. It is e

Communications between the user and the server A significant enhancement was achieved when communications between the user and the server was sent in encrypted form and later

What are the Input devices Various devices are available for data input on graphics workstations. Most systems have a keyboard and one or more additional devices specially desi

Define nondeterministic TM?  Arbitrarily chooses move when more than one possibility exists Accepts if there is at least one computation that terminates in an acceptin

What are assembler directives? Ans: These are the instructions that direct the program to be executed. They have no binary corresponding so they are called pseudo-opcodes. The

A Canvas object gives access to a Graphics object by its paint() method.