Skip to content
Permalink
8e7ea971bc
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
44 lines (36 sloc) 1.3 KB
;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