Skip to content

Instantly share code, notes, and snippets.

@piotrmaslanka
Created December 10, 2014 22:49
Show Gist options
  • Save piotrmaslanka/224f25f8419834a490d4 to your computer and use it in GitHub Desktop.
Save piotrmaslanka/224f25f8419834a490d4 to your computer and use it in GitHub Desktop.
DOS COM file. Multiply two numbers and write the result out in hex. Sure does requires a 32-bit processor due to referencing 32-bit registers in 16-bit mode. I'm just lazy.
; - kompilowac asemblerem NASM. skompiluje sie jako plik .com
[org 0x100]
start:
; zainicjuj rejestry segmentowe
push cs
pop ds
.mnozenie:
mov ax, 0x100
mov bx, 0x20F
mul bx ; - teraz starszy word wyniku jest w DX, a mlodszy w AX. Scal to
.scal_do_ecx:
mov ecx, edx
shl ecx, 16
or cx, ax
; - teraz wynik jest w rejestrze ECX. Musimy to wyprowadzic.
mov si, 8 ; - liczba ma 8 znakow hex, wiec tyle razy powtarzamy convert
.konwert:
push si ; - zapamietaj ile jeszcze powtorzyc
push ecx
mov edx, ecx
shr edx, 28 ; teraz w DL jest najstarsze nibble ECX
mov bp, convert_lut ; pobierz adres znaku po konwersji
add bp, dx
mov dl, byte [ds:bp]
mov ah, 02h ; - ustaw rozkaz wypisania znaku na ekran
int 21h ; - wypisz znak
pop ecx
shl ecx, 4
.sprawdz_czy_powtorzyc:
pop si
dec si
jnz .konwert
.koniec:
mov ah, 4Ch ; - rozkaz koniec programu
mov al, 0 ; - kod bledu 0
int 21h ; - koniec programu
convert_lut db '0123456789ABCDEF'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment