Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;Given a vector of DIM word in memory, replace it with reverse vector (without using another vector support)
- ;BEFORE AFTER
- ;423 9
- ;3191 3
- ;23 -412
- ;11 11
- ;-412 23
- ;3 3191
- ;9 423
- ;1° SOLUTION:
- DIM EQU 7
- .MODEL small
- .STACK
- .DATA
- vett DW 423, 3191, 23, 11, -412, 3, 9
- .CODE
- .STARTUP
- MOV CX, DIM/2 ;I write so because I will use XCHG instruction that exchanges the values of two operands, then it will cycle DIM/2 times
- XOR SI,SI
- MOV DI,(DIM-1)*2 ;DI takes the value of index of last element, in fact vett is DW, so, first to all, I do
- ;DIM-1 because vector's index starts from 0, and then I multiply for 2 because, being DW,
- ;I slide vector's cells two by two, because DW's dimension is 16 bit
- ciclo: MOV AX,vett[SI]
- XCHG vett[DI],AX ;By XCHG I exchange values of two operands
- MOV vett[SI],AX
- ADD SI,2
- SUB DI,2
- DEC CX
- CMP CX,0
- JNZ ciclo
- .EXIT
- END
- ;2° SOLUTION:
- DIM EQU 7
- .MODEL small
- .STACK
- .DATA
- vett DW 423, 3191, 23, 11, -412, 3, 9
- .CODE
- .STARTUP
- MOV CX,DIM
- XOR SI,SI ;I initialize SI to 0
- ciclo1: PUSH vett[SI] ;PUSH takes value of vett[SI]
- ;and places it into stack memory, on top
- ADD SI,2
- DEC CX
- CMP CX,0
- JNZ ciclo1
- MOV CX,DIM
- XOR SI,SI
- ciclo2: POP vett[SI] ;POP takes values that I placed into stack memory
- ;and places them into vett[SI]
- ADD SI,2
- DEC CX
- CMP CX,0
- JNZ ciclo2
- .EXIT
- END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement