Exercises

Anonymous
Assembly x86
09/10/2025 4:40 AM
2.0 KB
22
Indexable
Never
Exercise 1:

section .data

msg db "Hello, World!", 10 ; Message string with newline

len equ $ - msg ; Compute string length

section .text

global _start

_start:

; -- sys_write(fd=1, buf=msg, count=len) --

mov eax, 4        ; syscall number 4 = sys_write

mov ebx, 1        ; file descriptor = 1 (stdout)

mov ecx, msg      ; pointer to string

mov edx, len      ; string length

int 0x80          ; make kernel call

; -- sys_exit(status=0) --

mov eax, 1        ; syscall number 1 = sys_exit

xor ebx, ebx      ; exit code = 0

int 0x80


Exercise 2:
section .data

msg1 db "Hello, World!", 10

len1 equ $ - msg1

msg2 db "This is NASM 32-bit.", 10

len2 equ $ - msg2

section .text

global _start

_start:

; -- print msg1 --

mov eax, 4

mov ebx, 1

mov ecx, msg1

mov edx, len1

int 0x80

; -- print msg2 --

mov eax, 4

mov ebx, 1

mov ecx, msg2

mov edx, len2

int 0x80

; -- exit --

mov eax, 1

xor ebx, ebx

int 0x80


Exercise 3:
section .data

src db "Hello from .bss!", 10

srclen equ $ - src

section .bss

buf resb 32 ; Reserve 32-byte buffer

section .text

global _start

_start:

; -- copy string into buffer --

mov esi, src        ; source address

mov edi, buf        ; destination address

mov ecx, srclen     ; number of bytes to copy

cld                 ; copy forward

rep movsb           ; copy [esi] → [edi]

; -- print buffer --

mov eax, 4          ; sys_write

mov ebx, 1          ; stdout

mov ecx, buf        ; buffer address

mov edx, srclen     ; number of bytes

int 0x80

; -- exit --

mov eax, 1

xor ebx, ebx

int 0x80


Exercise 4:
section .data

msg db "Hello, World!", 10

len equ $ - msg

section .text

global _start

_start:

mov eax, 4        ; sys_write

mov ebx, 1        ; stdout

mov ecx, msg      ; address of string

mov edx, 5        ; only 5 characters ("Hello")

int 0x80

mov eax, 1        ; sys_exit

xor ebx, ebx

int 0x80
Editor is loading...
Leave a Comment