Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using assembly language (HCS12) Question: Define a 64-bit constant signed intege

ID: 3786966 • Letter: U

Question

Using assembly language (HCS12)

Question:

Define a 64-bit constant signed integer in Flash. Write a program that would divide it by 8 and stores the result in a 64-bit signed integer variable.

Write a subroutine count_1s that would count the number of 1s in a byte. The subroutine will receive the input parameter in A and return the result back in A. Use this subroutine to write a program that would count the number of 1s inside the 64-bit constant integer that you defined in 5.1. Define a variable that would hold the total count of 1s.

General explanation given by instructor:

shift by three right, arithmetic shift (signed), signed so first is 1, shift the first 16 byte (words) to the right by 2 to keep the sign. Then the bit from the shift will have a carry. Then the rest rotate right. With every rotate there is a carry and the next time gets the carry. There will be one shift and three rotates.

Explanation / Answer

main:

ldi zl, low(data*2)
ldi zh, high(data*2)
lpm r0, Z
srl ro, 3 //Divide by 8 routine i.e right shift three times

mov r1, #0 (initialize R1 and R6 to zero)
mov r6, #0
count_1s: and r6, r6, r0, srl #1 //Right shift by 1, right most bit is in carry flag)

addcs r1, #1 //Add #1 to r1 if carry flag is set)
cmp r0, #0 //update the status flags if r0 == 0 or not)
beq count_1s

data:
A .word 0x0000000000000100 //wtites number 8 to flash memory

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote