Skip to content

Instantly share code, notes, and snippets.

@biern
Created May 4, 2011 16:49
Show Gist options
  • Save biern/955551 to your computer and use it in GitHub Desktop.
Save biern/955551 to your computer and use it in GitHub Desktop.
## - stałe systemowe -
.equ kernel, 0x80
.equ stdout, 1
.equ exit, 0x01
.equ write, 0x04
.data
text:
.ascii "lorem ipsum .dolor sit, amet!\n(lol)\nlol2\n"
text_len:
.long ( . - text)
current:
.byte 'X'
# udajemy że poprzednim znakiem (indeks -1) była kropka - ułatwia sprawę
prev:
.byte '.'
.equ space, ' '
.equ dot, '.'
.equ newline, '\n'
.equ low_a, 'a'
.equ low_z, 'z'
.equ to_upper_delta, 32
.text
.global _start
_start:
MOVL text_len, %ecx
XOR %esi, %esi
text_loop:
PUSH %ecx
MOV text(,%esi,1), %al
MOV %al, current
double_space_check:
## Sprawdzamy czy to spacja
CMP $space, %al
JNE to_upper_check
## Sprawdzamy czy takie same
MOV prev, %bl
CMP current, %bl
JNE to_upper_check
double_space:
## Nic nie wypisujemy
JMP continue
to_upper_check:
## upewniamy się że wszystko jest tam gdzie powinno być
MOV prev, %bl
MOV current, %al
## Sprawdzamy czy jesteśmy po kropce lub spacji
CMP $space, %bl
JE to_upper_check_2
CMP $dot, %bl
JE to_upper_check_2
CMP $newline, %bl
JE to_upper_check_2
JNE write_char
to_upper_check_2:
## Sprawdzamy czy to mała litera alfabetu
## 'a' > c -> continue
CMP $low_a, %al
JB write_char
## 'z' < c -> continue
CMP $low_z, %al
JA write_char
to_upper:
## Powiększamy znak
SUB $to_upper_delta, %al
MOV %al, current
JMP write_char
write_char:
MOVL $write, %eax
MOVL $stdout, %ebx
MOVL $current, %ecx
MOVL $1, %edx
INT $kernel
continue:
MOVL current, %ebx
MOVL %ebx, prev
INC %esi
POP %ecx
LOOP text_loop
quit:
MOV $exit, %eax
INT $kernel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment