1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
|
<Comment>; </Comment><SPDX Tag>SPDX-FileCopyrightText:</SPDX Tag><Comment> 2025 Leo Marušić <leomarusic7@gmail.com></Comment><br/>
<Comment>; </Comment><SPDX Tag>SPDX-License-Identifier:</SPDX Tag><SPDX Value> </SPDX Value><SPDX License>MIT</SPDX License><br/>
<Label>MAIN:</Label><br/>
<Normal Text> </Normal Text><Bitwise Instruction>MOV</Bitwise Instruction><Normal Text> </Normal Text><Register>SP</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Number>#</Number><Hex>0x10000</Hex><Normal Text> </Normal Text><Comment>; stack initialization</Comment><br/>
<Normal Text> </Normal Text><Load/Store Instruction>LDR</Load/Store Instruction><Normal Text> </Normal Text><Register>R0</Register><Symbol>,</Symbol><Normal Text> MEM </Normal Text><Comment>; pointer to the address of the operands</Comment><br/>
<Normal Text> </Normal Text><Load/Store Instruction>LDR</Load/Store Instruction><Normal Text> </Normal Text><Register>R12</Register><Symbol>,</Symbol><Normal Text> REZ </Normal Text><Comment>; pointer for the result address</Comment><br/>
<Label>MAINLOOP:</Label><br/>
<Normal Text> </Normal Text><Arithmetic Instruction>ADD</Arithmetic Instruction><Normal Text> </Normal Text><Register>R0</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Register>R0</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Number>#</Number><Hex>0x8</Hex><Normal Text> </Normal Text><Comment>; point to the operation in the operand block</Comment><br/>
<Normal Text> </Normal Text><Load/Store Instruction>LDR</Load/Store Instruction><Normal Text> </Normal Text><Register>R1</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Symbol>[</Symbol><Register>R0</Register><Symbol>]</Symbol><Normal Text> </Normal Text><Comment>; save the operation code in R1</Comment><br/>
<Normal Text> </Normal Text><Arithmetic Instruction>CMP</Arithmetic Instruction><Normal Text> </Normal Text><Register>R1</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Number>#</Number><Hex>0x0</Hex><Normal Text> </Normal Text><Comment>; check for subtraction</Comment><br/>
<Normal Text> </Normal Text><Branch Instruction>BEQ</Branch Instruction><Normal Text> SUBTRACT</Normal Text><br/>
<Normal Text> </Normal Text><Arithmetic Instruction>CMP</Arithmetic Instruction><Normal Text> </Normal Text><Register>R1</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Number>#</Number><Hex>0x1</Hex><Normal Text> </Normal Text><Comment>; check for addition</Comment><br/>
<Normal Text> </Normal Text><Branch Instruction>BEQ</Branch Instruction><Normal Text> ADDLOOP</Normal Text><br/>
<Normal Text> </Normal Text><Arithmetic Instruction>CMP</Arithmetic Instruction><Normal Text> </Normal Text><Register>R1</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Number>#</Number><Hex>0x2</Hex><Normal Text> </Normal Text><Comment>; check for multiplication</Comment><br/>
<Normal Text> </Normal Text><Branch Instruction>BEQ</Branch Instruction><Normal Text> MULLOOP</Normal Text><br/>
<Normal Text> </Normal Text><Arithmetic Instruction>CMP</Arithmetic Instruction><Normal Text> </Normal Text><Register>R1</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Number>#</Number><Hex>0x3</Hex><Normal Text> </Normal Text><Comment>; check for division</Comment><br/>
<Normal Text> </Normal Text><Branch Instruction>BEQ</Branch Instruction><Normal Text> DIVIDEOP</Normal Text><br/>
<Normal Text> </Normal Text><Bitwise Instruction>MVN</Bitwise Instruction><Normal Text> </Normal Text><Register>R2</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Number>#</Number><Hex>0x0</Hex><Normal Text> </Normal Text><Comment>; put 0xFFFFFFFF in R2</Comment><br/>
<Normal Text> </Normal Text><Arithmetic Instruction>CMP</Arithmetic Instruction><Normal Text> </Normal Text><Register>R1</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Register>R2</Register><Normal Text> </Normal Text><Comment>; check for the end</Comment><br/>
<Normal Text> </Normal Text><Branch Instruction>BEQ</Branch Instruction><Normal Text> FINISH</Normal Text><br/>
<Normal Text> </Normal Text><Branch Instruction>B</Branch Instruction><Normal Text> MAINLOOP </Normal Text><Comment>; go back to the loop</Comment><br/>
<Normal Text></Normal Text><br/>
<Label>SUBTRACT:</Label><br/>
<Normal Text> </Normal Text><Arithmetic Instruction>SUB</Arithmetic Instruction><Normal Text> </Normal Text><Register>R0</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Register>R0</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Number>#</Number><Hex>0x8</Hex><Normal Text> </Normal Text><Comment>; go back to the beginning of the operand block</Comment><br/>
<Normal Text> </Normal Text><Load/Store Instruction>LDR</Load/Store Instruction><Normal Text> </Normal Text><Register>R1</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Symbol>[</Symbol><Register>R0</Register><Symbol>]</Symbol><Normal Text> </Normal Text><Comment>; load the first operand</Comment><br/>
<Normal Text> </Normal Text><Load/Store Instruction>LDR</Load/Store Instruction><Normal Text> </Normal Text><Register>R2</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Symbol>[</Symbol><Register>R0</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Number>#</Number><Hex>0x4</Hex><Symbol>]</Symbol><Normal Text> </Normal Text><Comment>; load the second operand</Comment><br/>
<Normal Text> </Normal Text><Arithmetic Instruction>SUB</Arithmetic Instruction><Normal Text> </Normal Text><Register>R3</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Register>R1</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Register>R2</Register><Normal Text> </Normal Text><Comment>; subtract</Comment><br/>
<Normal Text> </Normal Text><Load/Store Instruction>STR</Load/Store Instruction><Normal Text> </Normal Text><Register>R3</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Symbol>[</Symbol><Register>R12</Register><Symbol>]</Symbol><Normal Text> </Normal Text><Comment>; save the result</Comment><br/>
<Normal Text> </Normal Text><Arithmetic Instruction>ADD</Arithmetic Instruction><Normal Text> </Normal Text><Register>R12</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Register>R12</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Number>#</Number><Hex>0x4</Hex><Normal Text> </Normal Text><Comment>; move the result address pointer</Comment><br/>
<Normal Text> </Normal Text><Arithmetic Instruction>ADD</Arithmetic Instruction><Normal Text> </Normal Text><Register>R0</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Register>R0</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Number>#</Number><Hex>0xC</Hex><Normal Text> </Normal Text><Comment>; move the operand address pointer</Comment><br/>
<Normal Text> </Normal Text><Branch Instruction>B</Branch Instruction><Normal Text> MAINLOOP</Normal Text><br/>
<Normal Text></Normal Text><br/>
<Label>ADDLOOP:</Label><br/>
<Normal Text> </Normal Text><Arithmetic Instruction>SUB</Arithmetic Instruction><Normal Text> </Normal Text><Register>R0</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Register>R0</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Number>#</Number><Hex>0x8</Hex><Normal Text> </Normal Text><Comment>; go back to the beginning of the operand block</Comment><br/>
<Normal Text> </Normal Text><Load/Store Instruction>LDR</Load/Store Instruction><Normal Text> </Normal Text><Register>R1</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Symbol>[</Symbol><Register>R0</Register><Symbol>]</Symbol><Normal Text> </Normal Text><Comment>; load the first operand</Comment><br/>
<Normal Text> </Normal Text><Load/Store Instruction>LDR</Load/Store Instruction><Normal Text> </Normal Text><Register>R2</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Symbol>[</Symbol><Register>R0</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Number>#</Number><Hex>0x4</Hex><Symbol>]</Symbol><Normal Text> </Normal Text><Comment>; load the second operand</Comment><br/>
<Normal Text> </Normal Text><Arithmetic Instruction>ADD</Arithmetic Instruction><Normal Text> </Normal Text><Register>R3</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Register>R1</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Register>R2</Register><Normal Text> </Normal Text><Comment>; add</Comment><br/>
<Normal Text> </Normal Text><Load/Store Instruction>STR</Load/Store Instruction><Normal Text> </Normal Text><Register>R3</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Symbol>[</Symbol><Register>R12</Register><Symbol>]</Symbol><Normal Text> </Normal Text><Comment>; save the result</Comment><br/>
<Normal Text> </Normal Text><Arithmetic Instruction>ADD</Arithmetic Instruction><Normal Text> </Normal Text><Register>R12</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Register>R12</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Number>#</Number><Hex>0x4</Hex><Normal Text> </Normal Text><Comment>; move the result address pointer</Comment><br/>
<Normal Text> </Normal Text><Arithmetic Instruction>ADD</Arithmetic Instruction><Normal Text> </Normal Text><Register>R0</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Register>R0</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Number>#</Number><Hex>0xC</Hex><Normal Text> </Normal Text><Comment>; move the operand address pointer</Comment><br/>
<Normal Text> </Normal Text><Branch Instruction>B</Branch Instruction><Normal Text> MAINLOOP</Normal Text><br/>
<Normal Text></Normal Text><br/>
<Label>MULLOOP:</Label><br/>
<Normal Text> </Normal Text><Arithmetic Instruction>SUB</Arithmetic Instruction><Normal Text> </Normal Text><Register>R0</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Register>R0</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Number>#</Number><Hex>0x8</Hex><Normal Text> </Normal Text><Comment>; go back to the beginning of the operand block</Comment><br/>
<Normal Text> </Normal Text><Load/Store Instruction>LDR</Load/Store Instruction><Normal Text> </Normal Text><Register>R1</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Symbol>[</Symbol><Register>R0</Register><Symbol>]</Symbol><Normal Text> </Normal Text><Comment>; load the first operand</Comment><br/>
<Normal Text> </Normal Text><Load/Store Instruction>LDR</Load/Store Instruction><Normal Text> </Normal Text><Register>R2</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Symbol>[</Symbol><Register>R0</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Number>#</Number><Hex>0x4</Hex><Symbol>]</Symbol><Normal Text> </Normal Text><Comment>; load the second operand</Comment><br/>
<Normal Text> </Normal Text><Multiplication Instruction>MUL</Multiplication Instruction><Normal Text> </Normal Text><Register>R3</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Register>R1</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Register>R2</Register><Normal Text> </Normal Text><Comment>; multiply</Comment><br/>
<Normal Text> </Normal Text><Load/Store Instruction>STR</Load/Store Instruction><Normal Text> </Normal Text><Register>R3</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Symbol>[</Symbol><Register>R12</Register><Symbol>]</Symbol><Normal Text> </Normal Text><Comment>; save the result</Comment><br/>
<Normal Text> </Normal Text><Arithmetic Instruction>ADD</Arithmetic Instruction><Normal Text> </Normal Text><Register>R12</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Register>R12</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Number>#</Number><Hex>0x4</Hex><Normal Text> </Normal Text><Comment>; move the result address pointer</Comment><br/>
<Normal Text> </Normal Text><Arithmetic Instruction>ADD</Arithmetic Instruction><Normal Text> </Normal Text><Register>R0</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Register>R0</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Number>#</Number><Hex>0xC</Hex><Normal Text> </Normal Text><Comment>; move the operand address pointer</Comment><br/>
<Normal Text> </Normal Text><Branch Instruction>B</Branch Instruction><Normal Text> MAINLOOP</Normal Text><br/>
<Normal Text></Normal Text><br/>
<Label>DIVIDEOP:</Label><br/>
<Normal Text> </Normal Text><Arithmetic Instruction>SUB</Arithmetic Instruction><Normal Text> </Normal Text><Register>R0</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Register>R0</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Number>#</Number><Hex>0x8</Hex><Normal Text> </Normal Text><Comment>; go back to the beginning of the operand block</Comment><br/>
<Normal Text> </Normal Text><Load/Store Instruction>LDR</Load/Store Instruction><Normal Text> </Normal Text><Register>R1</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Symbol>[</Symbol><Register>R0</Register><Symbol>]</Symbol><Normal Text> </Normal Text><Comment>; load the first operand</Comment><br/>
<Normal Text> </Normal Text><Load/Store Instruction>LDR</Load/Store Instruction><Normal Text> </Normal Text><Register>R2</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Symbol>[</Symbol><Register>R0</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Number>#</Number><Hex>0x4</Hex><Symbol>]</Symbol><Normal Text> </Normal Text><Comment>; load the second operand</Comment><br/>
<Normal Text> </Normal Text><Arithmetic Instruction>SUB</Arithmetic Instruction><Normal Text> </Normal Text><Register>SP</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Register>SP</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Number>#</Number><Hex>0x4</Hex><Normal Text> </Normal Text><Comment>; space for the result</Comment><br/>
<Normal Text> </Normal Text><Load/Store Instruction>STMFD</Load/Store Instruction><Normal Text> </Normal Text><Register>SP</Register><Symbol>!,</Symbol><Normal Text> </Normal Text><Symbol>{</Symbol><Register>R1</Register><Symbol>-</Symbol><Register>R2</Register><Symbol>}</Symbol><Normal Text> </Normal Text><Comment>; put the operands on the stack</Comment><br/>
<Normal Text> </Normal Text><Branch Instruction>BL</Branch Instruction><Normal Text> DIVIDE</Normal Text><br/>
<Normal Text> </Normal Text><Arithmetic Instruction>ADD</Arithmetic Instruction><Normal Text> </Normal Text><Register>SP</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Register>SP</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Number>#</Number><Hex>0x8</Hex><Normal Text> </Normal Text><Comment>; stack cleanup</Comment><br/>
<Normal Text> </Normal Text><Load/Store Instruction>LDMFD</Load/Store Instruction><Normal Text> </Normal Text><Register>SP</Register><Symbol>!,</Symbol><Normal Text> </Normal Text><Symbol>{</Symbol><Register>R3</Register><Symbol>}</Symbol><Normal Text> </Normal Text><Comment>; retrieve the result</Comment><br/>
<Normal Text> </Normal Text><Load/Store Instruction>STR</Load/Store Instruction><Normal Text> </Normal Text><Register>R3</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Symbol>[</Symbol><Register>R12</Register><Symbol>]</Symbol><Normal Text> </Normal Text><Comment>; save the result</Comment><br/>
<Normal Text> </Normal Text><Arithmetic Instruction>ADD</Arithmetic Instruction><Normal Text> </Normal Text><Register>R12</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Register>R12</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Number>#</Number><Hex>0x4</Hex><Normal Text> </Normal Text><Comment>; move the result address pointer</Comment><br/>
<Normal Text> </Normal Text><Arithmetic Instruction>ADD</Arithmetic Instruction><Normal Text> </Normal Text><Register>R0</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Register>R0</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Number>#</Number><Hex>0xC</Hex><Normal Text> </Normal Text><Comment>; move the operand address pointer</Comment><br/>
<Normal Text> </Normal Text><Branch Instruction>B</Branch Instruction><Normal Text> MAINLOOP</Normal Text><br/>
<Normal Text></Normal Text><br/>
<Label>DIVIDE:</Label><br/>
<Normal Text> </Normal Text><Load/Store Instruction>STMFD</Load/Store Instruction><Normal Text> </Normal Text><Register>SP</Register><Symbol>!,</Symbol><Normal Text> </Normal Text><Symbol>{</Symbol><Register>R3</Register><Symbol>-</Symbol><Register>R5</Register><Symbol>}</Symbol><Normal Text> </Normal Text><Comment>; save the context</Comment><br/>
<Normal Text> </Normal Text><Load/Store Instruction>LDR</Load/Store Instruction><Normal Text> </Normal Text><Register>R3</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Symbol>[</Symbol><Register>SP</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Number>#</Number><Decimal>12</Decimal><Symbol>]</Symbol><Normal Text> </Normal Text><Comment>; load the numerator</Comment><br/>
<Normal Text> </Normal Text><Load/Store Instruction>LDR</Load/Store Instruction><Normal Text> </Normal Text><Register>R4</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Symbol>[</Symbol><Register>SP</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Number>#</Number><Decimal>16</Decimal><Symbol>]</Symbol><Normal Text> </Normal Text><Comment>; load the denominator</Comment><br/>
<Normal Text> </Normal Text><Bitwise Instruction>MOV</Bitwise Instruction><Normal Text> </Normal Text><Register>R5</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Number>#</Number><Decimal>0</Decimal><Normal Text> </Normal Text><Comment>; quotient</Comment><br/>
<Normal Text> </Normal Text><Arithmetic Instruction>CMP</Arithmetic Instruction><Normal Text> </Normal Text><Register>R4</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Number>#</Number><Hex>0x0</Hex><Normal Text> </Normal Text><Comment>; check for division by zero</Comment><br/>
<Normal Text> </Normal Text><Branch Instruction>BEQ</Branch Instruction><Normal Text> ZERO</Normal Text><br/>
<Normal Text></Normal Text><br/>
<Normal Text> </Normal Text><Arithmetic Instruction>CMP</Arithmetic Instruction><Normal Text> </Normal Text><Register>R3</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Number>#</Number><Decimal>0</Decimal><Normal Text> </Normal Text><Comment>; check if the numerator is negative</Comment><br/>
<Normal Text> </Normal Text><Bitwise Instruction>MVNLT</Bitwise Instruction><Normal Text> </Normal Text><Register>R3</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Register>R3</Register><Normal Text> </Normal Text><Comment>; 1's complement</Comment><br/>
<Normal Text> </Normal Text><Arithmetic Instruction>ADDLT</Arithmetic Instruction><Normal Text> </Normal Text><Register>R3</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Register>R3</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Number>#</Number><Decimal>1</Decimal><Normal Text> </Normal Text><Comment>; 2's complement</Comment><br/>
<Normal Text> </Normal Text><Arithmetic Instruction>CMP</Arithmetic Instruction><Normal Text> </Normal Text><Register>R4</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Number>#</Number><Decimal>0</Decimal><Normal Text> </Normal Text><Comment>; check if the denominator is negative</Comment><br/>
<Normal Text> </Normal Text><Bitwise Instruction>MVNLT</Bitwise Instruction><Normal Text> </Normal Text><Register>R4</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Register>R4</Register><Normal Text> </Normal Text><Comment>; 1's complement</Comment><br/>
<Normal Text> </Normal Text><Arithmetic Instruction>ADDLT</Arithmetic Instruction><Normal Text> </Normal Text><Register>R4</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Register>R4</Register><Normal Text> </Normal Text><Symbol>,</Symbol><Normal Text> </Normal Text><Number>#</Number><Decimal>1</Decimal><Normal Text> </Normal Text><Comment>; 2's complement</Comment><br/>
<Normal Text></Normal Text><br/>
<Label>LOOP1:</Label><br/>
<Normal Text> </Normal Text><Arithmetic Instruction>CMP</Arithmetic Instruction><Normal Text> </Normal Text><Register>R3</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Register>R4</Register><Normal Text> </Normal Text><Comment>; compare the numerator and the denominator</Comment><br/>
<Normal Text> </Normal Text><Branch Instruction>BLT</Branch Instruction><Normal Text> DONE </Normal Text><Comment>; if the numerator is less than the denominator, the division is finished</Comment><br/>
<Normal Text> </Normal Text><Arithmetic Instruction>SUB</Arithmetic Instruction><Normal Text> </Normal Text><Register>R3</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Register>R3</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Register>R4</Register><Normal Text> </Normal Text><Comment>; subtract the denominator from the numerator</Comment><br/>
<Normal Text> </Normal Text><Arithmetic Instruction>ADD</Arithmetic Instruction><Normal Text> </Normal Text><Register>R5</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Register>R5</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Number>#</Number><Decimal>1</Decimal><Normal Text> </Normal Text><Comment>; increment the quotient</Comment><br/>
<Normal Text> </Normal Text><Branch Instruction>B</Branch Instruction><Normal Text> LOOP1</Normal Text><br/>
<Normal Text></Normal Text><br/>
<Label>DONE:</Label><br/>
<Normal Text> </Normal Text><Arithmetic Instruction>CMP</Arithmetic Instruction><Normal Text> </Normal Text><Register>R1</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Number>#</Number><Decimal>0</Decimal><Normal Text> </Normal Text><Comment>; check the sign of the original numerator</Comment><br/>
<Normal Text> </Normal Text><Bitwise Instruction>MVNLT</Bitwise Instruction><Normal Text> </Normal Text><Register>R5</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Register>R5</Register><Normal Text> </Normal Text><Comment>; 1's complement the quotient</Comment><br/>
<Normal Text> </Normal Text><Arithmetic Instruction>ADDLT</Arithmetic Instruction><Normal Text> </Normal Text><Register>R5</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Register>R5</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Number>#</Number><Decimal>1</Decimal><Normal Text> </Normal Text><Comment>; 2's complement the quotient</Comment><br/>
<Normal Text> </Normal Text><Arithmetic Instruction>CMP</Arithmetic Instruction><Normal Text> </Normal Text><Register>R2</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Number>#</Number><Decimal>0</Decimal><Normal Text> </Normal Text><Comment>; check the sign of the original denominator</Comment><br/>
<Normal Text> </Normal Text><Bitwise Instruction>MVNLT</Bitwise Instruction><Normal Text> </Normal Text><Register>R5</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Register>R5</Register><Normal Text> </Normal Text><Comment>; 1's complement the quotient</Comment><br/>
<Normal Text> </Normal Text><Arithmetic Instruction>ADDLT</Arithmetic Instruction><Normal Text> </Normal Text><Register>R5</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Register>R5</Register><Normal Text> </Normal Text><Symbol>,</Symbol><Normal Text> </Normal Text><Number>#</Number><Decimal>1</Decimal><Normal Text> </Normal Text><Comment>; 2's complement the quotient</Comment><br/>
<Normal Text> </Normal Text><Load/Store Instruction>STR</Load/Store Instruction><Normal Text> </Normal Text><Register>R5</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Symbol>[</Symbol><Register>SP</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Number>#</Number><Decimal>20</Decimal><Symbol>]</Symbol><Normal Text> </Normal Text><Comment>; put the result on the stack</Comment><br/>
<Normal Text> </Normal Text><Load/Store Instruction>LDMFD</Load/Store Instruction><Normal Text> </Normal Text><Register>SP</Register><Symbol>!,</Symbol><Normal Text> </Normal Text><Symbol>{</Symbol><Register>R3</Register><Symbol>-</Symbol><Register>R5</Register><Symbol>}</Symbol><Normal Text> </Normal Text><Comment>; restore the context</Comment><br/>
<Normal Text> </Normal Text><Bitwise Instruction>MOV</Bitwise Instruction><Normal Text> </Normal Text><Register>PC</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Register>LR</Register><br/>
<Normal Text></Normal Text><br/>
<Label>ZERO:</Label><br/>
<Normal Text> </Normal Text><Load/Store Instruction>STR</Load/Store Instruction><Normal Text> </Normal Text><Register>R5</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Symbol>[</Symbol><Register>SP</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Number>#</Number><Decimal>20</Decimal><Symbol>]</Symbol><Normal Text> </Normal Text><Comment>; save zero as the result on the stack</Comment><br/>
<Normal Text> </Normal Text><Load/Store Instruction>LDMFD</Load/Store Instruction><Normal Text> </Normal Text><Register>SP</Register><Symbol>!,</Symbol><Normal Text> </Normal Text><Symbol>{</Symbol><Register>R3</Register><Symbol>-</Symbol><Register>R5</Register><Symbol>}</Symbol><Normal Text> </Normal Text><Comment>; restore the context</Comment><br/>
<Normal Text> </Normal Text><Bitwise Instruction>MOV</Bitwise Instruction><Normal Text> </Normal Text><Register>PC</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Register>LR</Register><br/>
<Normal Text></Normal Text><br/>
<Label>FINISH:</Label><br/>
<Normal Text> </Normal Text><Bitwise Instruction>MVN</Bitwise Instruction><Normal Text> </Normal Text><Register>R11</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Number>#</Number><Hex>0x0</Hex><Normal Text> </Normal Text><Comment>; marker for the end of the output</Comment><br/>
<Normal Text> </Normal Text><Load/Store Instruction>STR</Load/Store Instruction><Normal Text> </Normal Text><Register>R11</Register><Symbol>,</Symbol><Normal Text> </Normal Text><Symbol>[</Symbol><Register>R12</Register><Symbol>]</Symbol><Normal Text> </Normal Text><Comment>; save the marker at the end of the output</Comment><br/>
<Normal Text> </Normal Text><Special Instruction>SWI</Special Instruction><Normal Text> 0x123456</Normal Text><br/>
<Normal Text></Normal Text><br/>
<Label>MEM:</Label><Normal Text> </Normal Text><Control Statement>DW</Control Statement><Normal Text> 0x600 </Normal Text><Comment>; Memory for the operands</Comment><br/>
<Normal Text> </Normal Text><Control Statement>ORG</Control Statement><Normal Text> 0x600</Normal Text><br/>
<Normal Text> </Normal Text><Control Statement>DW</Control Statement><Normal Text> 0xFFFFFEFF</Normal Text><br/>
<Normal Text> </Normal Text><Control Statement>DW</Control Statement><Normal Text> 0x00000010</Normal Text><br/>
<Normal Text> </Normal Text><Control Statement>DW</Control Statement><Normal Text> 0x00000003</Normal Text><br/>
<Normal Text></Normal Text><br/>
<Normal Text> </Normal Text><Control Statement>DW</Control Statement><Normal Text> 0x000001F4</Normal Text><br/>
<Normal Text> </Normal Text><Control Statement>DW</Control Statement><Normal Text> 0xFFFFFD44</Normal Text><br/>
<Normal Text> </Normal Text><Control Statement>DW</Control Statement><Normal Text> 0x00000000</Normal Text><br/>
<Normal Text></Normal Text><br/>
<Normal Text> </Normal Text><Control Statement>DW</Control Statement><Normal Text> 0x00000003</Normal Text><br/>
<Normal Text> </Normal Text><Control Statement>DW</Control Statement><Normal Text> 0xFFFFFFEC</Normal Text><br/>
<Normal Text> </Normal Text><Control Statement>DW</Control Statement><Normal Text> 0x00000001</Normal Text><br/>
<Normal Text></Normal Text><br/>
<Normal Text> </Normal Text><Control Statement>DW</Control Statement><Normal Text> 0xFFFFFFFE</Normal Text><br/>
<Normal Text> </Normal Text><Control Statement>DW</Control Statement><Normal Text> 0x0000000A</Normal Text><br/>
<Normal Text> </Normal Text><Control Statement>DW</Control Statement><Normal Text> 0x00000002</Normal Text><br/>
<Normal Text></Normal Text><br/>
<Normal Text> </Normal Text><Control Statement>DW</Control Statement><Normal Text> 0xFFFFF000</Normal Text><br/>
<Normal Text> </Normal Text><Control Statement>DW</Control Statement><Normal Text> 0xFFFFFFC0</Normal Text><br/>
<Normal Text> </Normal Text><Control Statement>DW</Control Statement><Normal Text> 0x00000003</Normal Text><br/>
<Normal Text></Normal Text><br/>
<Normal Text> </Normal Text><Control Statement>DW</Control Statement><Normal Text> 0x00000001</Normal Text><br/>
<Normal Text> </Normal Text><Control Statement>DW</Control Statement><Normal Text> 0x00000004</Normal Text><br/>
<Normal Text> </Normal Text><Control Statement>DW</Control Statement><Normal Text> 0xFFFFFFFF</Normal Text><br/>
<Normal Text></Normal Text><br/>
<Label>RES:</Label><Normal Text> </Normal Text><Control Statement>DW</Control Statement><Normal Text> 0x2000 </Normal Text><Comment>; memory for the result</Comment><br/>
<Normal Text> </Normal Text><Control Statement>ORG</Control Statement><Normal Text> 0x2000</Normal Text><br/>
<Normal Text> </Normal Text><Control Statement>DW</Control Statement><Normal Text> 0x0000</Normal Text><br/>
<Normal Text> </Normal Text><Control Statement>DW</Control Statement><Normal Text> 0x0000</Normal Text><br/>
<Normal Text> </Normal Text><Control Statement>DW</Control Statement><Normal Text> 0x0000</Normal Text><br/>
<Normal Text> </Normal Text><Control Statement>DW</Control Statement><Normal Text> 0x0000</Normal Text><br/>
<Normal Text> </Normal Text><Control Statement>DW</Control Statement><Normal Text> 0x0000</Normal Text><br/>
<Normal Text> </Normal Text><Control Statement>DW</Control Statement><Normal Text> 0x0000</Normal Text><br/>
<Normal Text> </Normal Text><Control Statement>DW</Control Statement><Normal Text> 0x0000</Normal Text><br/>
<Normal Text> </Normal Text><Control Statement>DW</Control Statement><Normal Text> 0x0000</Normal Text><br/>
<Normal Text> </Normal Text><Control Statement>DW</Control Statement><Normal Text> 0x0000</Normal Text><br/>
<Normal Text> </Normal Text><Control Statement>DW</Control Statement><Normal Text> 0x0000</Normal Text><br/>
<Normal Text> </Normal Text><Control Statement>DW</Control Statement><Normal Text> 0x0000</Normal Text><br/>
<Normal Text> </Normal Text><Control Statement>DW</Control Statement><Normal Text> 0x0000</Normal Text><br/>
<Normal Text> </Normal Text><Control Statement>DW</Control Statement><Normal Text> 0x0000</Normal Text><br/>
|