Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions basic/typewriter_clock/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
all: typewriter_clock

typewriter_clock: typewriter_clock.asm
nasm -f elf32 typewriter_clock.asm -o typewriter_clock.o
ld -m elf_i386 typewriter_clock.o -o typewriter_clock

clean:
rm -f *.o typewriter_clock
13 changes: 13 additions & 0 deletions basic/typewriter_clock/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Typewriter Clock - x86 Assembly Tutorial

## Description
This is a simple x86 Assembly program that prints the current time in the terminal with a typewriter effect.

## Requirements
- Linux (tested on Debian/Ubuntu)
- NASM assembler

## Build and Run
```bash
make
./typewriter_clock
71 changes: 71 additions & 0 deletions basic/typewriter_clock/typewriter_clock.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
; typewriter_clock.asm - x86 Assembly (Linux ELF32)
; Typewriter clock: prints current time in terminal
; Compile: make
; Run: ./typewriter_clock

section .data
msg db "00:00:00", 0 ; placeholder for HH:MM:SS
len equ $ - msg
newline db 0x0A, 0 ; newline

section .bss
timebuf resb 9 ; HH:MM:SS\0

section .text
global _start

_start:
.loop:
; get current time from system
mov eax, 13 ; sys_time
xor ebx, ebx ; time_t *tloc = NULL
int 0x80

; simple conversion to HH:MM:SS (simplified)
mov ecx, 3600 ; seconds per hour
xor edx, edx
div ecx ; eax/3600 -> quotient=hours, remainder=minutes+seconds
add al, '0'
mov [timebuf], al

; minutes
mov eax, edx
mov ecx, 60
xor edx, edx
div ecx
add al, '0'
mov [timebuf+3], al

; seconds
mov al, dl
add al, '0'
mov [timebuf+6], al

; print with typewriter effect
mov esi, timebuf
.print_loop:
lodsb
cmp al, 0
je .done
mov eax, 4
mov ebx, 1
mov ecx, esi
dec ecx
mov edx, 1
int 0x80

; small delay
mov ecx, 50000
.delay:
loop .delay
jmp .print_loop

.done:
; new line
mov eax, 4
mov ebx, 1
mov ecx, newline
mov edx, 1
int 0x80

jmp .loop