210 likes | 220 Views
Learn how to create and manipulate linked lists using assembly language. See examples of building linked lists and stack allocation. Explore date and time stamping, cluster chains, array sum calculations, and array search recursively.
E N D
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.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 <Counter, ($ + Counter * SIZEOF ListNode)> ENDM ListNode <0,0> ; tail node
Linked list continued .code main PROC movesi,OFFSETLinkedList ; Display the integers in the NodeData members. NextNode: ; Check for the tail node. moveax,(ListNode PTR [esi]).NextPtr cmpeax,NULL je quit ; Display the node data. moveax,(ListNode PTR [esi]).NodeData call WriteDec call Crlf ; Get pointer to next node. movesi,(ListNode PTR [esi]).NextPtr jmpNextNode quit: exit main ENDP END main
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>
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 <0,0> ; tail node…not used .code
Linklist2 main main PROC push nullval push nullval;;;this is the tail ptr movesi,esp;;;current node address more: movedx,offset prompt call writestring call crlf call readint;;;;;;here is where we get data cmp eax,999 je doneInput movebp,esi push ebp ;;;this is the next node ptr push eax;;;this is the data movesi,esp;;;now this is the address of current node jmp more doneInput:
continued NextNode: ; Check for the tail node. moveax,(ListNode PTR [esi]).NextPtr cmpeax,NULL je quit ; Display the node data. moveax,(ListNode PTR [esi]).NodeData call WriteDec call Crlf ; Get pointer to next node. movesi,(ListNode PTR [esi]).NextPtr jmpNextNode quit: exit main ENDP END main
Date stamp Year = 0..119 and is added to 1980 Month=1..12 Day=1..31 month day 15 8 5 year 9
Time stamp Hour=0..23 Minute=0..59 Seconds=0..59 seconds hours minutes 0 15 5 11 10 4
Cluster chain example- just links are shown 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 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 File starts in cluster 5, size5
Arraysum recusive include irvine32.inc .data array dword 100, 200, 400, 300,700,900,800,500,600 .code main proc movesi,lengthof array decesi shl esi,2;esi is last subscript moveax,esi call writedec call crlf xoreax,eax call arraysum call writeDec main endp
continued arraysum proc call writedec call crlf cmp esi,0 jl L2 add eax,dwordptr array[esi] sub esi,4 call arraysum L2:ret arraysum endp end main
output 32 0 600 1100 1900 2800 3500 3800 4200 4400 4500 4500 <I inserted crlf here> 4500
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 movedx,offset message call writeString call crlf invoke arraysum, ADDR array,lengthof array call writedec call crlf exit main endp
continued arraysum proc USES esiecx,pArray:ptrDword,sz:Dword movecx,sz xoreax,eax movesi,pArray top: add eax,[esi] add esi,4 loop top ret arraysum endp end 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 .code main proc movesi,lengthof array decesi shlesi,2;esi is last subscript moveax,esi call writedec call crlf mov eax,501;;;wont find it call search moveax,ebx call writeInt ;;will write -1 for not found main endp
Recursive search proc search proc mov ebx,-1 cmp esi,0 jl L2 cmpeax,dwordptr array[esi] jnz skip movebx,esi shr ebx,2 jmp l2 skip: sub esi,4 call search L2:ret search endp end main
Writes last subscript then found value First run…look for 501 32 -1 Second run look for 500 32 +7 found in position 7