Permalink
Cannot retrieve contributors at this time
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?
Guessuing_Game/incrementExample (2).asm
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
44 lines (36 sloc)
1.3 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;Assembly code to show how to increment a variable and print the value | |
section .data | |
incMessage db "The inc value is :" | |
incMessageLen equ $-incMessage | |
cr db 10; newline | |
incValue db 5 ; the variable to be incremented | |
section .bss | |
section .text | |
global _start ;must be declared for using gcc | |
_start: ;tell linker entry point | |
inc byte [incValue] ; increment the value in the variable | |
mov eax, [incValue] ; move the incValue variable in eax | |
add eax, 48 ; convert the integer into ascii value to print | |
mov [incValue], eax ; Put the value back variable | |
; write the incremented statement to screen. | |
mov eax, 4 ; System call the screen | |
mov ebx, 1 ; standard out | |
mov ecx, incMessage; print inc message | |
mov edx, incMessageLen; Length of message | |
int 80h ; interrupt | |
; write the incremented value to screen. | |
mov eax, 4 ; System call the screen | |
mov ebx, 1 ; standard out | |
mov ecx, incValue; print value | |
mov edx, 1; One byte is size | |
int 80h ; interrupt | |
; write the incremented value to screen. | |
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 | |
; write the news line to screen. Same as endl in C++ | |
;exit program | |
mov eax,1 ;system call exit | |
int 0x80 ;call interrupt | |