Created
December 8, 2017 03:32
-
-
Save jasekiw/0f6849be0904ce3027dab10e2a933001 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
title N21 | |
.386 | |
.model flat,stdcall | |
.stack 4096 | |
ExitProcess proto, dwExitCode:dword | |
include Irvine32.inc | |
; | |
; Library | |
; | |
; Wite a point and an index | |
WritePoint proto, point: COORD, index: WORD | |
; Write a character | |
WriteCharacter proto, character: BYTE | |
COORD STRUCT | |
X WORD ? ; offset 00 | |
Y WORD ? ; offset 02 | |
COORD ENDS | |
; | |
; End Library | |
; | |
.data | |
coords COORD 10 DUP(<0,0>) | |
forward BYTE "------------- Forward -------------",0 | |
reverse BYTE "------------- Reverse -------------", 0 | |
.code | |
main proc | |
mov edx, OFFSET forward | |
call WriteString | |
call Crlf | |
mov eax, TYPE coords | |
mov ecx, LENGTHOF coords | |
mov esi, 0 | |
mov ax, 1 | |
Increment: | |
mov coords[esi].X, ax | |
mov bx, ax ; save the original index | |
add ax, 1 ; increment one to the index for the y coordinate | |
mov coords[esi].Y, ax ; coords[i].Y = i +1 | |
invoke WritePoint, coords[esi], bx ; WritePoint(coords[i], i) | |
add esi, TYPE coords | |
loop Increment | |
call Crlf ; put a blank line in there! | |
mov edx, OFFSET reverse | |
call WriteString | |
call Crlf | |
; Go backwards and print them out in reverse order | |
mov ecx, LENGTHOF coords | |
Decrement: | |
sub ax, 1 | |
sub esi, TYPE coords | |
invoke WritePoint, coords[esi], ax | |
loop Decrement | |
invoke ExitProcess,0 | |
main endp | |
; syntax sugar to reduce WriteChar to one line | |
WriteCharacter proc, character: BYTE | |
push eax | |
mov al, character | |
call WriteChar | |
pop eax | |
ret | |
WriteCharacter endp | |
WritePoint proc, point: COORD, index: WORD | |
push eax ; save eax | |
push esi ; save esi | |
mov eax, 0 ; reset eax so smaller numbers can be stored in ax | |
mov ax, index | |
call WriteDec ; write index | |
invoke WriteCharacter, '.' | |
invoke WriteCharacter, ' ' | |
invoke WriteCharacter, '(' | |
mov ax, point.X | |
call WriteDec | |
invoke WriteCharacter, ',' | |
invoke WriteCharacter, ' ' | |
mov ax, point.Y | |
call WriteDec | |
invoke WriteCharacter, ')' | |
call Crlf; | |
pop esi ; restore esi | |
pop eax ; restore eax | |
ret | |
WritePoint endp | |
end main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment