Presentation is loading. Please wait.

Presentation is loading. Please wait.

Link list/file stamps/clusters Odds and ends remaining for test 2.

Similar presentations


Presentation on theme: "Link list/file stamps/clusters Odds and ends remaining for test 2."— Presentation transcript:

1 Link list/file stamps/clusters Odds and ends remaining for test 2

2 Linklist output C:\Masm615>list 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

3 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.inc ListNode STRUCT NodeData DWORD ? NextPtr DWORD ? ListNode ENDS TotalNodeCount = 15 NULL = 0 Counter = 0.data LinkedList LABEL PTR ListNode REPT TotalNodeCount Counter = Counter + 1 ListNode ENDM ListNode ; tail node

4 Linked list continued.code main PROC mov esi,OFFSET LinkedList ; Display the integers in the NodeData members. NextNode: ; Check for the tail node. mov eax,(ListNode PTR [esi]).NextPtr cmp eax,NULL je quit ; Display the node data. mov eax,(ListNode PTR [esi]).NodeData call WriteDec call Crlf ; Get pointer to next node. mov esi,(ListNode PTR [esi]).NextPtr jmp NextNode quit: exit main ENDP END main

5 Linklist2 a linklist on the stack C:\Masm615>linklist2 enter numbers... 999 to quit 34 enter numbers... 999 to quit 56 enter numbers... 999 to quit 333 enter numbers... 999 to quit 12 enter numbers... 999 to quit 90 enter numbers... 999 to quit 609 enter numbers... 999 to quit 45 enter numbers... 999 to quit 32 enter numbers... 999 to quit 665 enter numbers... 999 to quit 435 enter numbers... 999 to quit 354 enter numbers... 999 to quit 09 enter numbers... 999 to quit 54 enter numbers... 999 to quit 999 54 9 354 435 665 32 45 609 90 12 333 56 34 C:\Masm615>

6 Linklist2…build arbitrary size list (up to stack allocation) ListNode STRUCT NodeData DWORD ? NextPtr DWORD ? ListNode ENDS TotalNodeCount = 15;;;not used NULL = 0 Counter = 0.data nullval dword 0 prompt byte "enter numbers... 999 to quit",0 ;;;;LinkedList LABEL PTR ListNode ListNode ; tail node…not used.code

7 Linklist2 main main PROC push nullval push nullval;;;this is the tail ptr mov esi,esp;;;current node address more: mov edx,offset prompt call writestring call crlf call readint;;;;;;here is where we get data cmp eax,999 je doneInput mov ebp,esi push ebp ;;;this is the next node ptr push eax;;;this is the data mov esi,esp;;;now this is the address of current node jmp more doneInput:

8 continued NextNode: ; Check for the tail node. mov eax,(ListNode PTR [esi]).NextPtr cmp eax,NULL je quit ; Display the node data. mov eax,(ListNode PTR [esi]).NodeData call WriteDec call Crlf ; Get pointer to next node. mov esi,(ListNode PTR [esi]).NextPtr jmp NextNode quit: exit main ENDP END main

9 Date stamp year 15 9 85 month day Year = 0..119 and is added to 1980 Month=1..12 Day=1..31

10 Time stamp 15 0 hoursminutes seconds Hour=0..23 Minute=0..59 Seconds=0..59 4 5 10 11

11 Cluster chain example- just links are shown 2348910eoc 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 File starting cluster=1, filesize=7

12 Cluster chain example#2- just links are shown 671112eoc 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 File starts in cluster 5, size5

13 Arraysum recusive include irvine32.inc.data array dword 100, 200, 400, 300,700,900,800,500,600.code main proc mov esi,lengthof array dec esi shl esi,2;esi is last subscript mov eax,esi call writedec call crlf xor eax,eax call arraysum call writeDec main endp

14 continued arraysum proc call writedec call crlf cmp esi,0 jl L2 add eax,dword ptr array[esi] sub esi,4 call arraysum L2:ret arraysum endp end main

15 output 32 0 600 1100 1900 2800 3500 3800 4200 4400 4500

16 Proto example from text: arraysum include irvine32.inc arraysum PROTO, parray: PTR DWORD,sz:DWORD.data array dword 10, 20, 30,40,60,50,70,80 message byte "here is the sum",0.code main proc mov edx,offset message call writeString call crlf invoke arraysum, ADDR array,lengthof array call writedec call crlf exit main endp

17 continued arraysum proc USES esi ecx,pArray:ptr Dword,sz:Dword mov ecx,sz xor eax,eax mov esi,pArray top: add eax,[esi] add esi,4 loop top ret arraysum endp end main

18 output here is the sum 360 Press any key to continue...

19 Array search recursive (using registers) include irvine32.inc.data array dword 100, 200, 400, 300,700,900,800,500,600.code main proc mov esi,lengthof array dec esi shl esi,2;esi is last subscript mov eax,esi call writedec call crlf mov eax,501;;;wont find it call search mov eax,ebx call writeInt ;;will write -1 for not found main endp

20 Recursive search proc search proc mov ebx,-1 cmp esi,0 jl L2 cmp eax,dword ptr array[esi] jnz skip mov ebx,esi shr ebx,2 jmp l2 skip: sub esi,4 call search L2:ret search endp end main

21 Writes last subscript then found value First run…look for 501 32 Second run look for 500 32 +7 found in position 7


Download ppt "Link list/file stamps/clusters Odds and ends remaining for test 2."

Similar presentations


Ads by Google