View
217
Download
2
Category
Tags:
Preview:
Citation preview
Link list/file stamps/clusters
Odds and ends remaining for test 2
Linklist output• C:\Masm615>list• 1• 2• 3• 4• 5• 6• 7• 8• 9• 10• 11• 12• 13• 14• 15
Linked list part1; This program shows how the STRUC directive; and the REPT directive can be combined to; create a linked list at assembly time.
INCLUDE Irvine32.incListNode STRUCT NodeData DWORD ? NextPtr DWORD ?ListNode ENDS
TotalNodeCount = 15NULL = 0Counter = 0.dataLinkedList LABEL PTR ListNodeREPT TotalNodeCount
Counter = Counter + 1ListNode <Counter, ($ + Counter * SIZEOF ListNode)>
ENDMListNode <0,0> ; tail node
Linked list continued.codemain PROC
mov esi,OFFSET LinkedList; Display the integers in the NodeData members.NextNode:
; Check for the tail node.mov eax,(ListNode PTR [esi]).NextPtrcmp eax,NULLje quit
; Display the node data.mov eax,(ListNode PTR [esi]).NodeDatacall WriteDeccall Crlf; Get pointer to next node.mov esi,(ListNode PTR [esi]).NextPtrjmp NextNode
quit:exit
main ENDPEND main
Linklist2 a linklist on the stackC:\Masm615>linklist2enter numbers... 999 to quit34enter numbers... 999 to quit56enter numbers... 999 to quit333enter numbers... 999 to quit12enter numbers... 999 to quit90enter numbers... 999 to quit609enter numbers... 999 to quit45enter numbers... 999 to quit32enter numbers... 999 to quit665enter numbers... 999 to quit435enter numbers... 999 to quit354enter numbers... 999 to quit09enter numbers... 999 to quit54enter numbers... 999 to quit999549354435665324560990123335634
C:\Masm615>
Linklist2…build arbitrary size list (up to stack allocation)
ListNode STRUCT NodeData DWORD ? NextPtr DWORD ?ListNode ENDS
TotalNodeCount = 15;;;not usedNULL = 0Counter = 0
.datanullval dword 0prompt byte "enter numbers... 999 to quit",0;;;;LinkedList LABEL PTR ListNode
ListNode <0,0> ; tail node…not used
.code
Linklist2 mainmain PROCpush nullvalpush nullval;;;this is the tail ptrmov esi,esp;;;current node addressmore:
mov edx,offset promptcall writestringcall crlfcall readint;;;;;;here is where we get datacmp eax,999je doneInputmov ebp,esipush ebp ;;;this is the next node ptrpush eax;;;this is the datamov esi,esp;;;now this is the address of current node
jmp moredoneInput:
continuedNextNode:
; Check for the tail node.mov eax,(ListNode PTR [esi]).NextPtrcmp eax,NULLje quit; Display the node data.mov eax,(ListNode PTR [esi]).NodeDatacall WriteDeccall Crlf
; Get pointer to next node.mov esi,(ListNode PTR [esi]).NextPtrjmp NextNode
quit:exit
main ENDPEND main
Date stamp
year15 9 8 5
month
day
Year = 0..119 and is added to 1980
Month=1..12
Day=1..31
Time stamp
150
hours minutesseconds
Hour=0..23
Minute=0..59
Seconds=0..59
45
1011
Cluster chain example- just links are shown
2 3 4 8 9 10 eoc
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
File starting cluster=1, filesize=7
Cluster chain example#2- just links are shown
6 7 11 12 eoc
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
File starts in cluster 5, size5
Arraysum recusiveinclude irvine32.inc.data array dword 100, 200, 400, 300,700,900,800,500,600.codemain procmov esi,lengthof arraydec esishl esi,2;esi is last subscriptmov eax,esicall writedeccall crlfxor eax,eaxcall arraysumcall writeDecmain endp
continuedarraysum proccall writedeccall crlfcmp esi,0jl L2add eax,dword ptr array[esi]
sub esi,4call arraysumL2:retarraysum endp
end main
output320600110019002800350038004200440045004500 <I inserted crlf here>4500
Proto example from text: arraysuminclude irvine32.incarraysum PROTO, parray: PTR DWORD,sz:DWORD.dataarray dword 10, 20, 30 ,40,60,50,70,80message byte "here is the sum",0.codemain procmov edx,offset messagecall writeStringcall crlfinvoke arraysum, ADDR array,lengthof array call writedeccall crlfexitmain endp
continued
arraysum proc USES esi ecx,pArray:ptr Dword,sz:Dword
mov ecx,szxor eax,eaxmov esi,pArraytop:add eax,[esi]add esi,4loop topretarraysum endpend main
output
• here is the sum• 360• Press any key to continue . . .
Array search recursive (using registers)include irvine32.inc
.data array dword 100, 200, 400, 300,700,900,800,500,600.codemain procmov esi,lengthof arraydec esishl esi,2;esi is last subscriptmov eax,esicall writedeccall crlfmov eax,501;;;wont find itcall searchmov eax,ebxcall writeInt ;;will write -1 for not found
main endp
Recursive search procsearch procmov ebx,-1
cmp esi,0jl L2cmp eax,dword ptr array[esi]jnz skipmov ebx,esishr ebx,2jmp l2skip:sub esi,4call searchL2:retsearch endp
end main
Writes last subscript then found value
First run…look for 50132-1Second run look for 50032+7 found in position 7
Recommended