You are on page 1of 2

Points to ponder (Laboratory 3).

Ahmed

Mohamed
Student
#:7641341

Square root algorithm flow chart and source code:

LOAD ACCA

LOAD REGX WITH

Source Code:
LDAA $(Variable)

LOAD ACCB WITH

LDX

#$0000

LDAB #$FF

INCREMENT B

LOOP INCB
INC X

INCB
INX

A<- (A-B)
N
O

SBA
A>B?

BHI
Y

HERE

BRA

LOOP
HERE

END

Square root program:


1 The BHI instruction should be used because in the code it comes right after
assembly instruction SBA which itself sets up flags in the Condition code register.
Our algorithm counts down the number we are trying to find the square root
therefore the BHI instruction checks if C+Z = 0 right after the instruction SBA, once
the right number is reached indicating that C+Z = 0 has been reached the program
will branch accordingly. If BGT is used the program will run fine but BGT works
with signed numbers and thus it will only work for numbers in the range
A={$00..$FF).
2 Program will round up to the nearest square root.

Precision Program:
3 The actual assembly syntax is BNE F6 , we dont need to because the assembler will
take care of this for us after the first loop through the code.
4 Precision refers to the amount of bytes per word we are going to be adding.
5 In our program the limitation is the risk of overwriting data to there our maximum
precision would be 082F-081F - C = 0010 -1 = A precision of 15.
6 The relationship is one to one, for example if our required precision is 3 our loop will
run 3 times.
7 Our augend is located in from locations 080D080F, and our Addend is located
081D-081F, both numbers are stored is BIG ENDIANS.
8 The program gets this from register B this information is manually specified by the
user in memory location 0830.
9 The instructions that affect the carry flag of the CCR are ADCA, ADCB and the CLC
all are able to affect the carry flag. The loop will run through 6 instructions before it
branches off. After the first addition the program will either set off a carry or not
next around the program will add the next significant byte of the second with
previously generated carry to accumulator a. And after the last addition of the last
two bytes the program will either set off a carry or not and then the instruction
ADCB will add #$00 to B along with the carry and put it in the least MSB of the
result. If CMPB #$00 were added before the BNE instruction the program would not
work because the carry would be overwritten in the condition code register and the
whole flow of our program would be different.

10 The program cannot add signed numbers because overflow will be not taken into
account and we would have to add an overflow detection source code in our
program depending on the overflow detection we could sign extend our result from
there.

You might also like