0% found this document useful (0 votes)
4 views2 pages

Calculate Product of Five Integers

The document is an assembly language program that prompts the user to enter five integers, stores them in an array, and calculates their product. It uses system calls to read input and print output messages. Finally, it displays the product and exits the program.

Uploaded by

barrowsgriffin10
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

Calculate Product of Five Integers

The document is an assembly language program that prompts the user to enter five integers, stores them in an array, and calculates their product. It uses system calls to read input and print output messages. Finally, it displays the product and exits the program.

Uploaded by

barrowsgriffin10
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

section .

data
prompt db "Enter an integer: ", 0
result_msg db "The product is: ", 0
array resd 5
product resd 1

section .bss
num resd 1

section .text
global _start

_start:
; Read five integers from the user
mov ecx, 5 ; Counter for 5 integers
lea rsi, array ; Load address of array

read_loop:
; Print prompt
mov rax, 1 ; syscall: write
mov rdi, 1 ; file descriptor: stdout
mov rsi, prompt ; message to write
mov rdx, 17 ; message length
syscall

; Read integer
mov rax, 0 ; syscall: read
mov rdi, 0 ; file descriptor: stdin
lea rsi, num ; buffer to store input
mov rdx, 4 ; number of bytes to read
syscall

; Convert string to integer


mov eax, [num] ; Load the input number
sub eax, '0' ; Convert ASCII to integer
mov [rsi], eax ; Store in array
add rsi, 4 ; Move to next array element
loop read_loop

; Calculate product
mov eax, 1 ; Initialize product to 1
lea rsi, array ; Load address of array
mov ecx, 5 ; Counter for 5 integers

product_loop:
mov ebx, [rsi] ; Load current integer
imul eax, ebx ; Multiply product
add rsi, 4 ; Move to next array element
loop product_loop

; Store product result


mov [product], eax

; Print result message


mov rax, 1 ; syscall: write
mov rdi, 1 ; file descriptor: stdout
mov rsi, result_msg ; message to write
mov rdx, 17 ; message length
syscall
; Print product
mov eax, [product] ; Load product
add eax, '0' ; Convert integer to ASCII
mov [num], eax ; Store in buffer for printing
mov rax, 1 ; syscall: write
mov rdi, 1 ; file descriptor: stdout
lea rsi, num ; message to write
mov rdx, 1 ; message length
syscall

; Exit program
mov rax, 60 ; syscall: exit
xor rdi, rdi ; status: 0
syscall

You might also like