Skip to navigation

Lander on the Acorn Archimedes

Maths (Geometry): AddVectors

Name: AddVectors [Show more] Type: Subroutine Category: Maths (Geometry) Summary: An unused routine that adds two vectors and uses self-modifying code to store the results in a specified location Deep dive: Unused code in Lander
Context: See this subroutine in context in the source code References: No direct references to this subroutine in this source file
.vmod1 ADD R4, R11, #xVertexRotated \ Modification code to store the result of \ the vector addition in xVertexRotated .vmod2 ADD R4, R11, #xCoord \ Modification code to restore the result of \ the vector addition to xCoord .vmod3 MOV R4, R12 \ Modification code to store the result of \ the vector addition in R12 .vmod4 ADD R4, R11, #xLandscapeCol \ Modification code to store the result of \ the vector addition in xLandscapeCol .vmod5 ADD R4, R11, #xLandscapeRow \ Modification code to store the result of \ the vector addition in xLandscapeRow .AddVectors STMFD R13!, {R14} \ Store the return address on the stack \ We now modify the following instruction in \ the AddVectorToVertices routine to change \ the way it works: \ \ ADD R3, R11, #xCoord \ \ Interestingly, though, none of the \ modifications above will work properly, as \ they all change R4 rather than R3, so \ presumably the modified subroutine was \ refactored and this unused routine wasn't \ updated \ \ If this routine worked, it would use the \ modifications to change the address where \ we stored the result LDR R1, vmod3 \ Modify the eighth instruction in the STR R1, AddVectorToVertices+28 \ AddVectorToVertices routine to the \ instruction in vmod3 LDMIA R0, {R0-R2} \ Fetch the coordinate from R0 into \ (R0, R1, R2) MOV R3, R12 \ Set R3 = R12 to use as the address of the \ second vector to add BL AddVectorToVertices+8 \ Add the vector (R0, R1, R2) to the vector \ at the address in R3 (by skipping the \ first two instructions in the modified \ routine LDR R1, vmod2 \ Revert the eighth instruction in the STR R1, AddVectorToVertices+28 \ AddVectorToVertices routine to the \ instruction in vmod2 (though note that \ this doesn't actually revert the \ instruction, it corrupts it, for the \ reasons noted above) LDMFD R13!, {PC} \ Return from the subroutine