Write an assembly language program in a file called hw6.asm. The program will ta
ID: 3821409 • 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 program for finding square root
DATA SEGMENT
DX DB 123 Number
AX DB 00 x value
CX DB 00 x-square value
DATA ENDS
CODE SEGMENT
ASSUME DS:DATA,CS:CODE
START:
L1: INC AX
MOV AX, BX
MUL BX
BEQ DX,BX, L1 (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 L3
JMP L2
L2: MOV AX,CX
L3: DEC AX
MOV CX
INT 21H
CODE ENDS
END START
OUTPUT:
11
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.