Circle Properties Write a program that prompts for and accepts the diameter of a circle as a floating point number. The program should calculate and output the area and circumference of the circle. A sample run of the program should look like this: Enter circle diameter: 2.5 The area is 4.91 and the circumference is 7.85.   Use 3.14159 as your constant for pi.     global main       ; exposes program entry point to the linker extern printf   ; declare external function extern scanf section .text   ; start of code segment main:    push rbp               ; preserve base pointer    mov rbp,rsp               ; copy stack pointer to base pointer    pop       rbp               ; restore base pointer    mov       rax, 0           ; exit status (0 = success)    ret section .data   ; start of initialized data segment section .bss   ; start of uninitialized data segment section .data prompt db "Enter circle diameter: ", 0 format db "The area is %0.2f and the circumference is %0.2f.", 0 pi dq 3.14159 section .bss diameter resq 1 radius resq 1 area resq 1 circumference resq 1 section .text global main extern printf extern scanf main: ; prompt the user for the diameter of the circle mov rdi, prompt mov eax, 0 call printf ; read the diameter from the user mov rdi, dword [diameter] mov rsi, "%lf" mov eax, 0 call scanf ; calculate the radius of the circle movsd xmm0, qword [diameter] movsd qword [radius], xmm0 movsd xmm0, qword [radius] divsd xmm0, qword 2 movsd qword [radius], xmm0 ; calculate the area of the circle movsd xmm0, qword [radius] movsd xmm1, qword [pi] mulsd xmm0, xmm0 mulsd xmm0, xmm1 movsd qword [area], xmm0 ; calculate the circumference of the circle movsd xmm0, qword [radius] movsd xmm1, qword [pi] addsd xmm0, xmm0 mulsd xmm0, xmm1 movsd qword [circumference], xmm0 ; output the results to the user mov rdi, format movsd xmm0, qword [area] movsd xmm1, qword [circumference] mov eax, 0 call printf ; exit the program mov eax, 0 ret

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

 

Circle Properties

Write a program that prompts for and accepts the diameter of a circle as a floating point number. The program should calculate and output the area and circumference of the circle.

A sample run of the program should look like this:

Enter circle diameter: 2.5

The area is 4.91 and the circumference is 7.85.

 

Use 3.14159 as your constant for pi.

 

 

global main       ; exposes program entry point to the linker
extern printf   ; declare external function
extern scanf

section .text   ; start of code segment

main:
   push rbp               ; preserve base pointer
   mov rbp,rsp               ; copy stack pointer to base pointer


   pop       rbp               ; restore base pointer
   mov       rax, 0           ; exit status (0 = success)
   ret

section .data   ; start of initialized data segment


section .bss   ; start of uninitialized data segment

section .data
prompt db "Enter circle diameter: ", 0
format db "The area is %0.2f and the circumference is %0.2f.", 0
pi dq 3.14159

section .bss
diameter resq 1
radius resq 1
area resq 1
circumference resq 1

section .text
global main
extern printf
extern scanf

main:
; prompt the user for the diameter of the circle
mov rdi, prompt
mov eax, 0
call printf

; read the diameter from the user
mov rdi, dword [diameter]
mov rsi, "%lf"
mov eax, 0
call scanf

; calculate the radius of the circle
movsd xmm0, qword [diameter]
movsd qword [radius], xmm0
movsd xmm0, qword [radius]
divsd xmm0, qword 2
movsd qword [radius], xmm0

; calculate the area of the circle
movsd xmm0, qword [radius]
movsd xmm1, qword [pi]
mulsd xmm0, xmm0
mulsd xmm0, xmm1
movsd qword [area], xmm0

; calculate the circumference of the circle
movsd xmm0, qword [radius]
movsd xmm1, qword [pi]
addsd xmm0, xmm0
mulsd xmm0, xmm1
movsd qword [circumference], xmm0

; output the results to the user
mov rdi, format
movsd xmm0, qword [area]
movsd xmm1, qword [circumference]
mov eax, 0
call printf

; exit the program
mov eax, 0
ret

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Mathematical functions
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education