Write an assembly language program in a file called hw6.asm. The program will ta
ID: 3817272 • Letter: W
Question
Write an assembly language program in a file called hw6.asm. The program will take a number specified in memory and compute the integer squareroot of the number. This is the integer that when squared will come the closest to the given number. For example: i squareroot (94) = 10;since 9^2 = 81 and 10^2 = 100 i squareroot (123) = 11;since 11^2 = 121 and 12^2 = 144 The integer squareroot computed should be placed in memory. The general algorithm to compute the integer squareroot is: x = 0; x_square = 0; while (x_squareExplanation / Answer
//ASm code for finding square root. this code for number 94
DATA SEGMENT
DX DB 94 Number
AX DB 00 x value
CX DB 00 x-square value
DATA ENDS
CODE SEGMENT
ASSUME DS:DATA,CS:CODE
START:
LOOP1: INC AX
MOV AX, BX
MUL BX
BEQ DX,BX, LOOP1 (BX<DX)x_square<number
MOV BX,CX
MOV AX,BX
MUL BX
MOV BX,AH AH->X_Square_new
DEC AX
MOV AX,BX
MUL BX
MOV BX,BH BH->X_square_old
SUB DX,AH
SUB DH,DX
CMP BH,AH x_square_new-number < number-x_squre_old
JGE LOOP3
JMP LOOP2
LOOP2: MOV AX,CX
LOOP3: DEC AX
MOV CX
INT 21H
CODE ENDS
END START
OUTPUT:
10
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.