22.1k views
0 votes
This question is for MASM ASSEMBLY 8086 microprocessor using Irvine32

Write a program that will calculate and print the perimeter of a circle with given radius of 5

INCLUDE Irvine32.inc
.data
radius WORD 5

User Sophana
by
9.5k points

1 Answer

4 votes

Below is an example of a MASM Assembly program using Irvine32 to calculate and print the perimeter of a circle with a given radius of 5:

INCLUDE Irvine32.inc

.data

radius WORD 5

pi DWORD 31416 ; Value of pi (approximation: 3.1416)

.code

main PROC

movzx eax, radius ; Load the radius into eax

imul eax, 2 ; Multiply the radius by 2 (diameter)

imul eax, pi ; Multiply the diameter by pi to get the perimeter

mov ebx, 10000 ; Scaling factor for decimal places

idiv ebx ; Divide by the scaling factor

call WriteDec ; Display the result

call Crlf

exit

main ENDP

END main

So, the above program figures out how long the edge of a circle is by using the formula: Perimeter = 2 * pi * radius. Pi is about 3. 1416

So, to use the code above, one need to have the Irvine32.inc file in the same directory as their program, and also set up well.

User Donato Azevedo
by
8.8k points