MASM Assembly Language x86 Processor. Must use windows32 framework
Write a non-recursive algorithm to find the greatest common divisor of two positive numbers.
. • Your program should read the two positive integers using dialog boxes. If they are not positive, a message box should be displayed with an appropriate message.
• Your program needs to have a procedure that takes two positive integers as parameters.
• You need to follow cdecl protocol for parameter passing.
• Display the valid result returned from your procedure using a message box
.586
.MODEL FLAT
INCLUDE io.h
.STACK 4096
.DATA
long DWORD ?
wide DWORD ?
prompt1 BYTE "Enter First Number?", 0
string BYTE 30 DUP (?)
prompt2 BYTE "Enter 2nd Number", 0
string BYTE 30 DUP (?)
prompt3 BYTE "greatest common divisor of two number is", 0
failure BYTE "Entered number is negative number", 0
.CODE
MAIN PROC
MOV AX, @DATA ; initialize DS
MOV DS, AX
LEA DX, prompt1 ; load and display the string in prompt1
MOV AH, 9
INT 21H
CALL CheckDec ; call the procedure for checking posive number
PUSH AX ; push reg AX onto the STACK
LEA DX, prompt2 ; load and display the string in prompt2
MOV AH, 9
INT 21H
CALL CheckDec ; call the procedure CheckDec
MOV BX, AX ; set BX=AX
POP AX ; pop a value from STACK into AX reg
@REPEAT: ; jump label
XOR DX, DX ; clear DX reg
DIV BX ; set AX=DX:AX\BX , AX=DX:AX%BX
CMP DX, 0 ;compare DX with 0
JE @END_LOOP ; jump to label END_LOOP if CX=0
MOV AX, BX ; set AX=BX
MOV BX, DX ; set BX=DX
JMP @LOOP ; jump to label REPEAT
@END_LOOP: ; jump label
LEA DX, prompt3 ; load and display the string PROMPT_3
MOV AH, 9
INT 21H
MOV AX, BX ; set AX=BX
CALL OutDecimal ; call the procedure OutDecimal
MOV AH, 4CH ; return control to DOS
INT 21H
MAIN ENDP
CheckDec PROC
; this procedureis used to read a number in decimal form
PUSH BX ; push BX reg onto the STACK
PUSH CX ; push CX reg onto the STACK
PUSH DX ; push DX reg onto the STACK
JMP @READ
@READ:
XOR BX, BX ; clear the BX reg
XOR CX, CX ; clear the CX reg
XOR DX, DX ; clear the DX reg
MOV AH, 1 ; set input function
INT 21H ; read a character
CMP AL, "-" ; compare AL with "-"
JE @MINUS ; jump to label MINUS if input no.="-"
@MINUS: ; jump label
LEA DX, failure ;display given no is negative number
AND AX, 000FH ; convert ascii code into decimal code
PUSH AX ; push AX onto the STACK
MOV AX, 10 ; set AX=10
MUL BX ; set AX=AX*BX
MOV BX, AX ; set BX=AX
POP AX ; pop a value from STACK into AX reg
ADD BX, AX ; set BX=AX+BX
JS @ERROR ; jump to label ERROR if SF=1
@ERROR:
MOV AH, 2 ; set output function
MOV DL, 7H ; set DL=7H
INT 21H ; print a character
XOR CH, CH ; clear CH
@CLEAR:
MOV DL, 8H ; set DL=8H
INT 21H ; print a character
MOV DL, 20H ; set DL=' '
INT 21H ; print a character
MOV DL, 8H ; set DL=8H
INT 21H ; print a character
LOOP @CLEAR ; jump to label CLEAR if CX!=0
JMP @READ ; jump to label READ
@END_INPUT: ; jump label
CMP CH, 1 ; compare CH with 1
JNE @EXIT ; jump to label EXIT if CH!=1
NEG BX ; negate BX
@EXIT: ; jump label
MOV AX, BX ; set AX=BX
POP DX ; pop a value from STACK into DX reg
POP CX ; pop a value from STACK into CX reg
POP BX ; pop a value from STACK into BX reg
RET ; return control to the calling procedure
CheckDec ENDP
OutDecimal PROC
; this procedure is used to display a decimal number
PUSH BX ; push BX onto the STACK
PUSH CX ; push CX onto the STACK
PUSH DX ; push DX onto the STACK
CMP AX, 0 ;compare AX with 0
JGE @START ; jump to label START if AX>=0 i.e positive
PUSH AX ; push AX onto the STACK
@START: ; jump label
XOR CX, CX ; clear CX
MOV BX, 10 ; set BX=10
@OUTPUT: ; loop label
XOR DX, DX ; clear DX
DIV BX ; divide AX by BX
PUSH DX ; push DX onto the STACK
INC CX ; increment CX
OR AX, AX ; take OR of Ax with AX for conditioning
JNE @OUTPUT ; jump to label OUTPUT if ZF=0 i.e conditioning
MOV AH, 2 ; set output function
@DISPLAY: ; loop label
POP DX ; pop a value from STACK to DX reg
OR DL, 30H ; convert decimal into ascii code
INT 21H ; print a character
LOOP @DISPLAY ; jump to label DISPLAY if CX!=0
POP DX ; pop a value from STACK into DX reg
POP CX ; pop a value from STACK into CX reg
POP BX ; pop a value from STACK into BX reg
RET ; return control to the calling procedure
OutDecimal ENDP
END MAIN
MASM Assembly Language x86 Processor. Must use windows32 framework Write a non-recursive algorithm to find the greatest...
MASM Assembly Language x86 Processor. Must use windows32 framework Write a non-recursive algorithm to find the greatest common divisor of two positive numbers. . • Your program should read the two positive integers using dialog boxes. If they are not positive, a message box should be displayed with an appropriate message. • Your program needs to have a procedure that takes two positive integers as parameters. • You need to follow cdecl protocol for parameter passing. • Display the valid...
INTEL 80x86 ASSEMBLY LANGUAGE CODE Write a windows32 assembly language program that utilizes a recursive procedure. The main (_MainProc) procedure should: accept, from the user, a positive integer. Guard against non-positive integers being entered using a loop. call the sumseries sub-procedure using the cdecl protocol, receive the results of the sub-procedure, and display the results. The sumseries sub-procedure should: recursively find the sum of the series: 1*2 + 2*3 + 3*4 + ... + i*(i+1) (This is an iterative definition....
Using SPIM, write and test a program that finds the Greatest Common Divisor of two integers using a recursive function that implements Euclid's GCD algorithm as described below. Your program should greet the user "Euclid's GCD algorithm", prompt the user to input two integers, and then output the result "Euclid's Greatest Common Divisor Algorithm" GCD(M,N) = M (if N is 0) GCD(M,N) = GCD(N, M % N) (if N > 0) you may assume that inputs are non-negative name your assembly...
IN PYTHON Write a recursive function for Euclid's algorithm to find the greatest common divisor (gcd) of two positive integers. gcd is the largest integer that divides evenly into both of them. For example, the gcd(102, 68) = 34. You may recall learning about the greatest common divisor when you learned to reduce fractions. For example, we can simplify 68/102 to 2/3 by dividing both numerator and denominator by 34, their gcd. Finding the gcd of huge numbers is an...
In Assembly Language Please display results and write assembler code in (gcd.s) The Euclidean algorithm is a way to find the greatest common divisor of two positive integers, a and b. First let me show the computations for a=210 and b=45. Divide 210 by 45, and get the result 4 with remainder 30, so 210=4·45+30. Divide 45 by 30, and get the result 1 with remainder 15, so 45=1·30+15. Divide 30 by 15, and get the result 2 with remainder...
Cryptography Computer Security Greatest Common Divisor Assignment Instructions In software, implement the Euclidean algorithm to find the greatest common divisor of any two positive integers. It should implement the pseudocode provided in the text. It should allow the user to enter two integers. Your program should output the intermediate values of q, r1, r2 for each step and should return the greatest common divisor. Challenge component: Allow the user's input to be zero as well as the positive integers. Provide...
Use R language to program Problem 1: Greatest Common Divisor (GCD) Please write two functions, g edi ) and gcdr , which both take two integers a, b and calculates their greatest common divisor (GCD) using the Euclidean algorithm gcdi () should do so using iteration while gcdr () should use recursion. Then write a third function, gcd(), which takes two integers a, band an optional third argument nethod which takes a charater string containing either "iterative" or "recursive", with...
Assembly Language Programming Assignment program must be in: MASM assembly language / x86 architecture / irvine library procedures Objectives: 1. using register indirect addressing 2. passing parameters 3. generating “random” numbers 4. working with arrays Description: Write and test a MASM program to perform the following tasks: 1. Introduce the program. 2. Generate ARRAYSIZE random integers in the range [LO = 10 .. HI = 29], storing them in consecutive elements of an array. ARRAYSIZE should be set to 200....
Write a MIPS assembly language for sorting an array of integers using non-recursive bottom-up merge sort algorithm. Your program should print the processed array after each step of the merge sort. For example, if the input array is 14 27 13 11 49 63 17 9, your program should print each sort process: Input Arra;y 14 27 13 11 49 63 17 9 Print After first Iteration 14 27 11 13 49 639 17 Print After second iteration 11 13...
PLEASE USE VERY BASIC REGISTERS AND CODE TO DO THE FOLLOWING Objectives: -write assembly language programs to: -define a recursive procedure/function and call it. -use syscall operations to display integers and strings on the console window -use syscall operations to read integers from the keyboard. Assignment Description: Implement a MIPS assembly language program that defines "main", and "function1" procedures. The function1 is recursive and should be defined as: function1(n) = (2*n)+9 if n <= 5 =...