Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- TITLE MASM Template (main.asm)
- INCLUDE Irvine32.inc
- NUMS_ROWS = 7d
- NUMS_COLS = 9d
- SWITCHES_LENGTH = 80d
- CHANGES_LENGTH = 20d
- SWITCHES_LENGTH = 20d
- .data
- ; 7 rows, 9 cols
- ; Initial data in array
- NUMS WORD 09EEBh, 0B0CFh, 061E5h, 089EDh, 0AF17h, 0D8D1h, 06C1Dh, 0594Eh, 0CF55h
- WORD 03767h, 063C6h, 0AE84h, 0412Fh, 0B226h, 046C1h, 0879Bh, 076B6h, 093FFh
- WORD 0AFFFh, 05B8Fh, 06164h, 01CF7h, 09A41h, 0A525h, 0A5A1h, 08F05h, 07E4Ch
- WORD 0827Ah, 090B0h, 0722Dh, 0BCCFh, 033ABh, 0DC76h, 085B6h, 0AA5Fh, 03FB3h
- WORD 04BACh, 0B822h, 07768h, 0BF1Bh, 05783h, 07EEBh, 09F22h, 0B85Bh, 05312h
- WORD 05971h, 0B1B6h, 0B16Dh, 054B3h, 073C8h, 0586Bh, 08170h, 06F16h, 092A0h
- WORD 09680h, 0A23Bh, 0B45Dh, 01E91h, 0415Ah, 0B5D9h, 02D02h, 06748h, 03D39h
- ; Elements to be swapped in array (stored in pair)
- SWITCHES BYTE 4,3, 1,0, 2,6, 3,6, 4,3, 5,3, 4,6, 0,1, 2,1, 5,2
- BYTE 5, 4, 5, 6, 5, 5, 4, 6, 1, 4, 3, 5, 1, 3, 2, 7, 3, 4, 2, 2
- BYTE 6, 7, 4, 6, 1, 4, 1, 8, 2, 3, 2, 6, 5, 8, 6, 3, 3, 7, 6, 1
- BYTE 0, 3, 4, 2, 2, 5, 4, 4, 5, 5, 2, 0, 5, 7, 6, 6, 5, 6, 3, 3
- ; Output strings
- strNUMS BYTE "Unsorted: ", 0
- strSORTED BYTE "Sorted: ", 0
- strADDED BYTE "Changed: ", 0
- strSWAPPED BYTE "Swapped: ", 0
- ; Returns the row-major-order index of a given element in NUMS
- ; Requires:
- ; eax - row
- ; ebx - col
- ; Returns:
- ; edx - RMO index
- GetIndex PROC uses eax
- ; eax is already the row
- mov edx, NUMS_COLS
- mul edx ; eax = row * TOTAL COLUMNS
- add eax, ebx ; eax = row * total columns + COLUMN
- mov edx, 2
- mul edx ; eax *= SIZE OF WORD
- mov edx, eax
- ret
- GetIndex ENDP
- DoSwitches PROC uses ecx eax ebx esi
- mov ecx, SWITCHES_LENGTH
- mov esi, OFFSET SWITCHES
- L1:
- mov eax, [esi] ; eax = row 1
- mov ebx, [esi+1] ; ebx = col 1
- call GetIndex ; edx = index 1
- mov eax, [esi+2] ; eax = row 2
- mov ebx, [esi+3] ; ebx = col 2
- push ecx
- mov ecx, edx ; ecx = index 1
- call GetIndex ; edx = index 2
- call DumpRegs
- mov ax, WORD PTR [NUMS+ecx]
- mov dx, WORD PTR [NUMS+edx]
- mov [WORD PTR NUMS+edx],ax
- mov [WORD PTR NUMS+ecx],bx
- pop ecx
- add esi, 4 ; move to next set of data
- loop L1
- ret
- DoSwitches ENDP
- main PROC
- call ClrScr
- mov edx, OFFSET strNUMS
- call WriteString
- call PrintNums
- mov edx, OFFSET strSORTED
- call WriteString
- call BubbleSort
- call PrintNums
- mov edx, OFFSET strADDED
- call WriteString
- call AddChanges
- call PrintNums
- mov edx, OFFSET strSWAPPED
- call WriteString
- call DoSwitches
- ;call PrintNums
- exit
- main ENDP
- END main
Add Comment
Please, Sign In to add comment