Write a short assembly subroutine to count the number of one

Write a short assembly subroutine to count the number of ones in the lower 4 bits of a register (TEMP 1). Test each bit one at a time. If the value of the bit Is \'1\' Increment a register (NUM_ ONES). If the value of the bit is \'0\', move on to the next bit in the register. Exit the subroutine when the lower 4 bits have been tested. Write the assembly Instructions to update all 13-bits of the program counter. The first entry in the lookup table below. Table - simple table- This contains a simple lookup table

Solution

A)

Lebel Mnemonics Comment

MVI NUM_ONES, 00H ; Initialize NUME_ONES register with all zeros

MOV A, TEMP1 ; Copy the data from TEMP1 to accumulator A.

RRC ;Rotate accumulator right

JC NEXT1 ; IF carry is 1 then jump to leble NEXT1

NEXT1 INR NUM_ONES ; Increment data of NUM_ONES by one

RRC ;Rotate accumulator right

  JC NEXT2 ; IF carry is 1 then jump to leble NEXT2

NEXT2 INR NUM_ONES ; Increment data of NUM_ONES by one

RRC ; Rotate accumulator right

  JC NEXT3 ; IF carry is 1 then jump to leble NEXT3

NEXT3 INR NUM_ONES ; Increment data of NUM_ONES by one

RRC ;Rotate accumulator right

JC NEXT4 ; IF carry is 1 then jump to leble NEXT4

NEXT4 INR NUM_ONES ; Add data of NUM_ONES to carry bit

HLT ; Halt the execution of subroutine

NOTE: This program can even be smaller if there is another register given for loop operation.

Acumulator and Carry register are assumed to be given because for ALU operation these are necessary register.

Mnemonics commands are choosen on the basis of 8085 microprocessor command.

B)

In question it is not given for which processor we have to update program counter.

The answer is written here for 8085 micro processor.

Objective: First load the PC with ABCD H, then load it again with 00 H.

It is very simple to load PC using a simple command PCHL in 8085, as given below...

Mnemonics Comment

LXI H, 0xABCD H ; Load the HL register pair direct with 0xADCD H

PCHL ; Copy the content of HL register pair to program counter (PC)

LXI H, 00H ; Load HL register pair with all zeros

PCHL ;Copy the content of HL register pair to program counter (PC)

HLT

 Write a short assembly subroutine to count the number of ones in the lower 4 bits of a register (TEMP 1). Test each bit one at a time. If the value of the bit
 Write a short assembly subroutine to count the number of ones in the lower 4 bits of a register (TEMP 1). Test each bit one at a time. If the value of the bit

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site