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

Write an assembly language program that give the square rootof an integer (integ

ID: 3610215 • Letter: W

Question

Write an assembly language program that give the square rootof an integer (integer part only). Must use subroutines. Programstarts at address x3000. Input must come from the keyboard. Outputmust go to the screen. Please include comments at each lineexplaining why it was done this way. Write an assembly language program that give the square rootof an integer (integer part only). Must use subroutines. Programstarts at address x3000. Input must come from the keyboard. Outputmust go to the screen. Please include comments at each lineexplaining why it was done this way.

Explanation / Answer

; SQUARE ROOT OF A NUMBER

.DATA                                ; Data segment starts at x3000
NUM1 DW 0019H               ; Initialize num1 to 0019
SQRT DW 01 DUP (?)          ; Reserve 1word of uninitialised data space to offset sqrt
.CODE                                 ; Code segment starts
START:
MOV AX,@DATA              ;Initialize data segment
MOV DS,AX
MOV AX,NUM1                 ;Move the number(num1) to AX
XOR BX,BX                      ;XOR is performed and result is stored in BX
MOV BX,0001H                  ;Initialize BX to 0001H
MOV CX,0001H                  ;Initialize CX to 0001H
LOOP1: SUB AX,BX          ;AX=AX-BX
JZ LOOP2                           ; If zero flag is zero jump to loop2
INC CX                               ; Increment CX by 1
ADD BX,0002H                  ;BX=BX+0002H
JMP LOOP1                        ; Jump to loop1
INC CX                               ; Increment CX by 1
LOOP2: MOV SQRT,CX      ; Store result
INT 03H                              ; halt
END START

INPUT:
NUM1 = 0019 H (25 IN DECIMAL)
NUM1 = 0090 H (144 IN DECIMAL)
OUTPUT:
RESULT = 0005H ( 5 IN DECIMAL)
RESULT = 000CH ( 12 IN DECIMAL)

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