Skip to content

Instantly share code, notes, and snippets.

@Gogotron
Created August 30, 2020 21:53
Show Gist options
  • Save Gogotron/1ae81d9c5fc6e2aa122b68a1d3210a16 to your computer and use it in GitHub Desktop.
Save Gogotron/1ae81d9c5fc6e2aa122b68a1d3210a16 to your computer and use it in GitHub Desktop.
Making an OS (x86) - Part 2 challenge
mov ah, 0x0e ; initialize ah
mov al, 'a' ; first letter
label: ; enter loop
int 0x10 ; print char
xor al, 32 ; switch from uppercase to lowercase or vice-versa,
inc al ; next letter
mov bl, al ; This checks if the last 5 digits of al are 11010
and bl, 31 ; meaning 26, without modifying it. This is the case
cmp bl, 26 ; for 'Z' and 'z' but not for any other ascii letter.
jle label ; The code loops as long as the end of al is less than or equal to 26.
jmp $ ; End of the program.
times 510-($-$$) db 0
db 0x55, 0xaa
@deijjji303
Copy link

Hey I also did the challenge and I don't quite understand what the jmp $ instruction in your code does.

@deijjji303
Copy link

Oh wait is that just an endless loop?

@Gogotron
Copy link
Author

Gogotron commented Apr 3, 2021

Oh wait is that just an endless loop?

Yes, exactly that, it jumps to itself, looping endlessly.

@NucleaTNT
Copy link

mov ah, 0x0e			; Switch to teletype mode
mov al, 'A'			; Initialize al with first letter
	
loop:
	int 0x10		; Output al to screen
	add al, 'a' - 'A'	; Move to lowercase ascii
	int 0x10		; Output al to screen
	sub al, 'a' - 'A' - 1	; Move to next UPPERCASE letter in ascii
	cmp al, 'Z' + 1		; Check if we've reached the end of the
	jne loop		; alphabet. If not, keep looping.

jmp $				; Infinite loop

Just skimmed it by one less line by making the switch between UPPER and lower also increment al. I'm sure you could implement it with your and command. Not that it really matters, I just enjoy seeing how little lines I can squish something into!

@NucleaTNT
Copy link

Oh wait is that just an endless loop?

Already been answered but for clarity $ in NASM Syntax is the current address/line the processor is executing. Therefore by telling the computer to jmp $ we're asking it "Jump to the beginning of this line again" and it'll continue jumping to itself infinitely. Just wanted to clear that up as it's used in the Bootloader Padding section of the code too ($ - $$).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment