Skip to content
Snippets Groups Projects
Commit 5743f153 authored by k26-chow's avatar k26-chow
Browse files

edited

parent fc192e5a
No related merge requests found
%include "asm_io.inc"
%include "asm_io.inc" ;
segment .data
prompt_name db "Enter your name: ", 0 ;
prompt_number db "Enter a number between 50 and 100: ", 0 ;
welcome_msg db "Welcome, ", 0 ;
newline db 10, 0 ;
prompt_name db "What is your name? ", 0 ;
prompt_count db "Enter a number between 50 and 100: ", 0 ;
welcome_msg db "Welcome, ", 0 ;
newline db 10, 0 ;
error_msg db "Error: The number must be between 50 and 100!", 0 ;
segment .bss
user_name resb 50 ;
user_input resd 1 ;
user_name resb 50 ;
name_length resd 1 ;
print_count resd 1 ;
section .text
segment .text
global asm_main
asm_main:
pusha ;
; Ask the user for their name
mov eax, prompt_name ;
call print_string ;
call read_string ;
; Ask the user for a number between 50 and 100
mov eax, prompt_number ;
mov edi, user_name ;
xor ecx, ecx ;
read_name_loop:
call read_char ;
cmp al, 10 ;
je name_input_done ;
mov [edi], al ;
inc edi ;
inc ecx ;
cmp ecx, 50 ;
jl read_name_loop ;
mov [name_length], ecx ;
mov byte [edi], 0 ;
mov eax, prompt_count ;
call print_string ;
call read_int ;
mov [user_input], eax ;
call read_int ;
mov [print_count], eax ;
; Check if the number is between 50 and 100
mov eax, [user_input] ;
; Validate the input range
mov eax, [print_count] ;
cmp eax, 50 ;
jle invalid_input ;
cmp eax, 100 ;
jge invalid_input ;
jl invalid_input ;
cmp eax, 100 ;
jg invalid_input ;
; If the number is valid, print the welcome message with the user's name
; If input is valid, print the welcome message `print_count` times
mov ecx, [print_count] ;
print_loop:
mov eax, welcome_msg ;
call print_string ;
mov eax, user_name ;
call print_string ;
call print_nl ;
; Print the welcome message the number of times entered by the user
mov ecx, [user_input] ;
print_welcome:
mov eax, welcome_msg ;
call print_string ;
call print_nl ;
loop print_welcome ;
jmp end_program ;
loop print_loop ;
jmp exit_program ;
invalid_input:
; Print the error message if the input is invalid
; Print the error message
mov eax, error_msg ;
call print_string ;
call print_nl ;
jmp asm_main ;
end_program:
popa ;
mov eax, 0 ;
ret
ret ;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment