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. Show typical microprocessor system architecture? A microprocessor system bus consists of three physical buses: the address bus, the data bus, and the control bus. The types

Q. Illustration to demonstrate design of sequential circuits? Let us take an illustration to demonstrate above process. Suppose we want to design 2-bit binary counter employing

What is Focussed Ion Beam Fix? A FIB Fix (Focussed Ion Beam) Fix is simply performed onto a terminated chip. FIB is a somewhat exotic process where a particle beam is capable t

Differentiate between static and dynamic step loops. Step loops fall into two classes: Static and Dynamic.  Static step loops have a fixed size that cannot be changed at runti

Design Patterns are easy and elegant solutions of commonly having problems in software design. Design Patterns make it simpler to reuse successful designs and architectures of expe

How numbering plan is achieved in modern telephony? Give the structure with example. The objective of numbering plan is to uniquely identify every subscriber connected to a tel

The real power of arrays comes from their facility of using an index variable to traverse the array, accessing every element with the similar expression a[i]. All the is required t

Find out the two inputs when the NAND gate output will be low. Ans. The output of NAND gate will be low if the two inputs are 11. The Truth Table of NAND gate is shown

Documentation is done to give others with information and ease maintenance. The best documentation is done in the headers (function and scripts) and directly in the code. Any usefu

IA-64 instead depends on the compiler for this task. Even before the program is fed into the CPU, the compiler studies the code and makes the similar sorts of decisions that would