Write Intel 8086 assembly programs use the NASM assembler 1

Write Intel 8086 assembly programs - use the NASM assembler.

1) Write a program called ONES to determine the number of bits equal to one in a 32-bit variable. The 32-bit variable is in memory location 0x0154. Store the 8-bit counter in memory location 0x0150.

2) Write a program called UNPACK to convert the 16-bit BCD variable in memory locations 0x0150 and 0x0151 to four ASCII
characters with the high-order digit first, beginning in memory location 0x0154.

Solution

Hey, So I would be answering the crux:

1. to be simple, and if efficieny is no a great concern, you can learn it as: for beginner):

//Initialise vars
mov num, [number] // use mem location :0x0154
while(nm!=0) // loop will run
{
div num, 2 // for modulo remainder
ifnum == 1){ // check for ones
ans++;
}
shr eax, 1; // now shift right the number // for next dividend
}
//after that store result
// now store ans here at memory location
//Note : also provide check for segmentatin fault

2. Regarding BCD : computers work internally with binary numbers, the input and output in sual uses decimal numbers:

Assembly instruction for that

//....

org 0x0150

org  0x0154

ldd data ; F = the number to be converted

ldy #res : U= the first address of result

Use idiv : ;D/X to X, r to D

then use addb command to convert the digit into ASCII code

stab 4,Y ;save the least significant digit

xgdx

//again repeat the procedure :ten

stab 3,Y ;save the least significant digit

//.. then 2, the, 1 and 0

Further as an improvement use  loop to reduce the program ..

Thanks

Write Intel 8086 assembly programs - use the NASM assembler. 1) Write a program called ONES to determine the number of bits equal to one in a 32-bit variable. T

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site