Last active
April 8, 2016 23:00
-
-
Save Delamare2112/a4526597f140ce5f0a202702b6d7d617 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
INCLUDE Irvine32.inc | |
newLine EQU 0Dh, 10, 0 | |
write MACRO string | |
mov edx, OFFSET string | |
call WriteString | |
ENDM | |
movmem MACRO dest, source | |
mov ebx, source | |
mov dest, ebx | |
ENDM | |
Node STRUCT | |
next DWORD ? | |
data DWORD ? | |
Node ENDS | |
List STRUCT | |
head DWORD 0 | |
List ENDS | |
.data | |
strPrompt BYTE "Please enter a value for a new node: ", newLine | |
strError BYTE "Error allocating memory", newLine | |
strBadInput BYTE "Invalid input try again...", newLine | |
strDisplay BYTE "Displaying List:", newline | |
strDone BYTE 0Dh, 10, "done", newline | |
strSeperator BYTE ", ", 0 | |
link List <0> | |
nextNodePtr DWORD OFFSET link.head | |
.code | |
Malloc PROC allocSize:dword | |
add allocSize, 4 | |
invoke GetProcessHeap | |
invoke HeapAlloc, eax, HEAP_ZERO_MEMORY, allocSize | |
.IF eax == 0 | |
write strError | |
.ENDIF | |
ret | |
Malloc ENDP | |
NewNode PROC val:DWORD | |
invoke Malloc, SIZEOF Node | |
mov esi, [nextNodePtr] | |
mov [esi], eax ; *nextNodePtr = malloc(SizeOf(Node)) | |
mov esi, [esi] | |
movmem [esi].Node.data, val ; **nextNodePtr.data = val | |
mov [esi].Node.next, 0 ; **nextNodePtr.next = 0 | |
mov nextNodePtr, esi ; nextNodePtr = &nextNodePtr.next | |
ret | |
NewNode ENDP | |
DisplayList PROC inLink:DWORD | |
LOCAL currNode:DWORD | |
mov esi, inLink | |
movmem currNode, (List PTR [esi]).head | |
.IF currNode == 0 | |
ret | |
.ENDIF | |
L1: | |
mov esi, currNode | |
mov eax, (Node PTR [esi]).data | |
call WriteDec | |
movmem currNode, (Node PTR [esi]).next | |
.IF currNode == 0 | |
ret | |
.ELSE | |
write strSeperator | |
jmp L1 | |
.ENDIF | |
DisplayList ENDP | |
GetUserNodes PROC | |
read: | |
write strPrompt | |
call ReadDec | |
jnc GoodInput | |
write strBadInput | |
jmp read | |
goodInput: | |
.IF eax == 0 | |
ret | |
.ENDIF | |
invoke NewNode, eax | |
GetUserNodes ENDP | |
main PROC | |
invoke GetUserNodes | |
write strDisplay | |
invoke DisplayList, OFFSET link | |
write strDone | |
call ReadChar | |
exit | |
main ENDP | |
END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment