Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
;Assembly code to write messages to file
section .data
scoreMsg db "Your score was: " ;Message for score
scoreMsgLen equ $-scoreMsg ; Ge the persons name
saveMsg db "The score is written to file " ;Message for score
saveMsgLen equ $-saveMsg ; Ge the persons name
score db '9' ; the score
cr db 10 ; newline like endl in C++
fileName db 'output.txt'
section .bss
fileWrite resb 1 ; store the id for the file
section .text
global _start ;must be declared for using gcc
_start: ;tell linker entry point
;; delete file at start
mov eax, 10 ; system call 10 to delete file
mov ebx, fileName ; file name to delete
int 80h ; interrupt
;create the file
mov eax, 8 ; system call the create file
mov ebx, fileName ; name of file to be created
mov ecx, 0777 ;Set file permission
int 80h ;call interrupt
mov [fileWrite], eax ; File identifier
; write score and message to file
mov edx, scoreMsgLen ;Size of message
mov ecx, scoreMsg ;message to be written to file
mov ebx, [fileWrite] ;file id for saving
mov eax,4 ;system call write
int 80h ;interrupt
; write score in the file
mov edx, 1 ;Size of score in bytes
mov ecx, score ;message to write
mov ebx, [fileWrite] ;file descriptor
mov eax,4 ;system call number (sys_write)
int 0x80 ;call kernel
; write into the file newline
mov edx, 1 ;One bytes
mov ecx, cr ;newline like endl in C++
mov ebx, [fileWrite] ;file id
mov eax,4 ;system call for writing
int 80h ;interrupt
;close the file
mov eax, 6 ; system call to close the file
mov ebx, [fileWrite] ; file id
int 80h; inteuupt
; write the message to screen that written information to file
mov eax, 4
mov ebx, 1
mov ecx, saveMsg
mov edx, saveMsgLen
int 80h
; write the news line to screen. Same as endl in C++
mov eax, 4 ; System call the screen
mov ebx, 1 ; standard out
mov ecx, cr ; newline
mov edx, 1; One byte is size
int 80h ; interrupt
;exit program
mov eax,1 ;system call exit
int 0x80 ;call interrupt