Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
OS_WorkSheet1
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
k26-chow
OS_WorkSheet1
Commits
5743f153
Commit
5743f153
authored
4 months ago
by
k26-chow
Browse files
Options
Downloads
Patches
Plain Diff
edited
parent
fc192e5a
Loading
Loading
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/task2.asm
+40
-33
40 additions, 33 deletions
src/task2.asm
with
40 additions
and
33 deletions
src/task2.asm
+
40
−
33
View file @
5743f153
%include "asm_io.inc"
%include "asm_io.inc"
;
seg
ment
.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
;
seg
ment
.bss
user_name
resb
50
;
user_input
resd
1
;
user_name
resb
50
;
name_length
resd
1
;
print_count
resd
1
;
se
ction
.text
se
g
ment
.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_inpu
t
],
eax
;
call
read_int
;
mov
[
print_coun
t
],
eax
;
;
Check if the number is between 50 and 100
mov
eax
,
[
user_inpu
t
]
;
;
Validate the input range
mov
eax
,
[
print_coun
t
]
;
cmp
eax
,
50
;
jl
e
invalid_input
;
cmp
eax
,
100
;
jg
e
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
;
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment