Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
os_worksheet
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_worksheet
Commits
58ef79ae
Commit
58ef79ae
authored
6 months ago
by
k26-chow
Browse files
Options
Downloads
Patches
Plain Diff
Delete task2.asm
parent
aef46c25
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
task2.asm
+0
-81
0 additions, 81 deletions
task2.asm
with
0 additions
and
81 deletions
task2.asm
deleted
100644 → 0
+
0
−
81
View file @
aef46c25
int
__attribute__
((
cdecl
))
asm_main
(
void
)
;
int
main
()
{
int
ret_status
;
ret_status
=
asm_main
()
;
return
ret_status
;
}
nasm
-
f
elf
task2.asm
-
o
task2.o
nasm
-
f
elf
asm_io.asm
-
o
asm_io.o
gcc
-
m32
-
c
driver.c
-
o
driver.o
gcc
-
m32
driver.o
task2.o
asm_io.o
-
o
task2
%include "asm_io.inc"
; Include I/O functions (like print_string, read_int, read_string)
seg
ment
.data
prompt_name
db
"
Enter
your
name
:
"
,
0
; Prompt for name
prompt_number
db
"
Enter
a
number
between
50
and
100
:
"
,
0
; Prompt for number
welcome_msg
db
"Welcome, "
,
0
; Welcome message
newline
db
10
,
0
; Newline character
error_msg
db
"
Error
:
The
number
must
be
between
50
and
100
!"
,
0
; Error message
seg
ment
.bss
user_name
resb
50
; Reserve 50 bytes for the user's name
user_input
resd
1
; Reserve space for user input (the number)
section
.text
global
asm_main
asm_main:
pusha
; Save all registers
; Ask the user for their name
mov
eax
,
prompt_name
; Load the prompt_name address into EAX
call
print_string
; Print the name prompt
call
read_string
; Read the user's name into user_name
; Ask the user for a number between 50 and 100
mov
eax
,
prompt_number
; Load the prompt_number address into EAX
call
print_string
; Print the number prompt
call
read_int
; Read the user's input into EAX (the number)
mov
[
user_input
],
eax
; Store the user's input in user_input
; Check if the number is between 50 and 100
mov
eax
,
[
user_input
]
; Load the user input into EAX
cmp
eax
,
50
; Compare the number to 50
jle
invalid_input
; Jump to invalid_input if number is <= 50
cmp
eax
,
100
; Compare the number to 100
jge
invalid_input
; Jump to invalid_input if number is >= 100
; If the number is valid, print the welcome message with the user's name
mov
eax
,
welcome_msg
; Load the welcome message into EAX
call
print_string
; Print the welcome message
mov
eax
,
user_name
; Load the user's name into EAX
call
print_string
; Print the user's name
call
print_nl
; Print a newline
; Print the welcome message the number of times entered by the user
mov
ecx
,
[
user_input
]
; Set ECX (loop counter) to the user input number
print_welcome:
mov
eax
,
welcome_msg
; Load the welcome message into EAX
call
print_string
; Print the welcome message
call
print_nl
; Print a newline
loop
print_welcome
; Loop until ECX (the number) is 0
jmp
end_program
; Jump to end_program after printing the welcome messages
invalid_input:
; Print the error message if the input is invalid
mov
eax
,
error_msg
; Load the error message into EAX
call
print_string
; Print the error message
call
print_nl
; Print a newline
jmp
asm_main
; Ask for the input again
end_program:
popa
; Restore registers
mov
eax
,
0
; Return 0 to indicate successful execution
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