Skip to content
Snippets Groups Projects
Commit a70d8489 authored by v2-nenavath's avatar v2-nenavath
Browse files

done

parent ce7875b4
No related branches found
No related tags found
No related merge requests found
No preview for this file type
hello: driver.c
gcc -o driver.o -c driver.c
File deleted
%include "asm_io.inc"
section .data
prompt_name db "Enter your name: ", 0
prompt_times db "Enter the number of times to print the welcome message (50-100): ", 0
error_msg db "Error: Number must be between 50 and 100.", 0
welcome_msg db "Welcome, ", 0
newline db 10, 0
section .bss
user_name resb 20 ; Reserve 20 bytes for the name
num_times resd 1 ; Reserve space for number of times to print
section .text
global asm_main
asm_main:
enter 0, 0
pusha
; Ask for the number of times to print
mov eax, prompt_times
call print_string
call read_int ; Read the number into EAX
mov [num_times], eax ; Store the number in num_times
; Validate the number (50 <= num_times <= 100)
mov eax, [num_times]
cmp eax, 50
jl invalid_input ; If num_times < 50, jump to error
cmp eax, 100
jg invalid_input ; If num_times > 100, jump to error
; Print welcome message 'num_times' times
mov ecx, [num_times]
print_loop:
mov eax, welcome_msg
call print_string ; Print "Welcome, "
call print_nl ; Print newline
loop print_loop ; Repeat 'num_times' times
jmp end_program ; Skip error section
invalid_input:
mov eax, error_msg
call print_string ; Print error message
call print_nl
end_program:
popa
mov eax, 0
leave
ret
task2.o 0 → 100644
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment