Branch
Hash :
554ff324
Author :
Date :
2022-03-21T15:25:14
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 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289
AREA subrout, CODE, READONLY ; Name this block of code
ENTRY ; Mark first instruction to execute
start MOV r0, #10 ; Set up parameters
MOV r1, #3
BL doadd ; Call subroutine
stop MOV r0, #0x18 ; angel_SWIreason_ReportException
LDR r1, =0x20026 ; ADP_Stopped_ApplicationExit
SVC #0x123456 ; ARM semihosting (formerly SWI)
doadd ADD r0, r0, r1 ; Subroutine code
BX lr ; Return from subroutine
END ; Mark end of file
MACRO
$Lab DivMod $Div,$Top,$Bot,$Temp
ASSERT $Top <> $Bot ; Produce an error message if the
ASSERT $Top <> $Temp ; registers supplied are
ASSERT $Bot <> $Temp ; not all different
IF "$Div" <> ""
ASSERT $Div <> $Top ; These three only matter if $Div
ASSERT $Div <> $Bot ; is not null ("")
ASSERT $Div <> $Temp ;
ENDIF
$Lab
MOV $Temp, $Bot ; Put divisor in $Temp
CMP $Temp, $Top, LSR #1 ; double it until
90 MOVLS $Temp, $Temp, LSL #1 ; 2 * $Temp > $Top
CMP $Temp, $Top, LSR #1
BLS %b90 ; The b means search backwards
IF "$Div" <> "" ; Omit next instruction if $Div is null
MOV $Div, #0 ; Initialize quotient
ENDIF
91 CMP $Top, $Temp ; Can we subtract $Temp?
SUBCS $Top, $Top,$Temp ; If we can, do so
IF "$Div" <> "" ; Omit next instruction if $Div is null
ADC $Div, $Div, $Div ; Double $Div
ENDIF
MOV $Temp, $Temp, LSR #1 ; Halve $Temp,
CMP $Temp, $Bot ; and loop until
BHS %b91 ; less than divisor
MEND
----------------------------------------------------
[
["directive", "AREA"],
" subrout",
["punctuation", ","],
["directive", "CODE"],
["punctuation", ","],
["directive", "READONLY"],
["comment", "; Name this block of code"],
["directive", "ENTRY"],
["comment", "; Mark first instruction to execute"],
"\r\nstart ",
["instruction", "MOV"],
["register", "r0"],
["punctuation", ","],
["operator", "#"],
["number", "10"],
["comment", "; Set up parameters"],
["instruction", "MOV"],
["register", "r1"],
["punctuation", ","],
["operator", "#"],
["number", "3"],
["instruction", "BL"],
" doadd ",
["comment", "; Call subroutine"],
"\r\nstop ",
["instruction", "MOV"],
["register", "r0"],
["punctuation", ","],
["operator", "#"],
["number", "0x18"],
["comment", "; angel_SWIreason_ReportException"],
["instruction", "LDR"],
["register", "r1"],
["punctuation", ","],
["operator", "="],
["number", "0x20026"],
["comment", "; ADP_Stopped_ApplicationExit"],
["instruction", "SVC"],
["operator", "#"],
["number", "0x123456"],
["comment", "; ARM semihosting (formerly SWI)"],
"\r\ndoadd ",
["instruction", "ADD"],
["register", "r0"],
["punctuation", ","],
["register", "r0"],
["punctuation", ","],
["register", "r1"],
["comment", "; Subroutine code"],
["instruction", "BX"],
["register", "lr"],
["comment", "; Return from subroutine"],
["directive", "END"],
["comment", "; Mark end of file"],
["directive", "MACRO"],
["variable", "$Lab"],
" DivMod ",
["variable", "$Div"],
["punctuation", ","],
["variable", "$Top"],
["punctuation", ","],
["variable", "$Bot"],
["punctuation", ","],
["variable", "$Temp"],
["directive", "ASSERT"],
["variable", "$Top"],
["operator", "<>"],
["variable", "$Bot"],
["comment", "; Produce an error message if the"],
["directive", "ASSERT"],
["variable", "$Top"],
["operator", "<>"],
["variable", "$Temp"],
["comment", "; registers supplied are"],
["directive", "ASSERT"],
["variable", "$Bot"],
["operator", "<>"],
["variable", "$Temp"],
["comment", "; not all different"],
["directive", "IF"],
["string", [
"\"",
["variable", "$Div"],
"\""
]],
["operator", "<>"],
["string", ["\"\""]],
["directive", "ASSERT"],
["variable", "$Div"],
["operator", "<>"],
["variable", "$Top"],
["comment", "; These three only matter if $Div"],
["directive", "ASSERT"],
["variable", "$Div"],
["operator", "<>"],
["variable", "$Bot"],
["comment", "; is not null (\"\")"],
["directive", "ASSERT"],
["variable", "$Div"],
["operator", "<>"],
["variable", "$Temp"],
["comment", ";"],
["directive", "ENDIF"],
["variable", "$Lab"],
["instruction", "MOV"],
["variable", "$Temp"],
["punctuation", ","],
["variable", "$Bot"],
["comment", "; Put divisor in $Temp"],
["instruction", "CMP"],
["variable", "$Temp"],
["punctuation", ","],
["variable", "$Top"],
["punctuation", ","],
" LSR ",
["operator", "#"],
["number", "1"],
["comment", "; double it until"],
["number", "90"],
["instruction", "MOVLS"],
["variable", "$Temp"],
["punctuation", ","],
["variable", "$Temp"],
["punctuation", ","],
" LSL ",
["operator", "#"],
["number", "1"],
["comment", "; 2 * $Temp > $Top"],
["instruction", "CMP"],
["variable", "$Temp"],
["punctuation", ","],
["variable", "$Top"],
["punctuation", ","],
" LSR ",
["operator", "#"],
["number", "1"],
["instruction", "BLS"],
["operator", "%"],
"b90 ",
["comment", "; The b means search backwards"],
["directive", "IF"],
["string", [
"\"",
["variable", "$Div"],
"\""
]],
["operator", "<>"],
["string", ["\"\""]],
["comment", "; Omit next instruction if $Div is null"],
["instruction", "MOV"],
["variable", "$Div"],
["punctuation", ","],
["operator", "#"],
["number", "0"],
["comment", "; Initialize quotient"],
["directive", "ENDIF"],
["number", "91"],
["instruction", "CMP"],
["variable", "$Top"],
["punctuation", ","],
["variable", "$Temp"],
["comment", "; Can we subtract $Temp?"],
["instruction", "SUBCS"],
["variable", "$Top"],
["punctuation", ","],
["variable", "$Top"],
["punctuation", ","],
["variable", "$Temp"],
["comment", "; If we can, do so"],
["directive", "IF"],
["string", [
"\"",
["variable", "$Div"],
"\""
]],
["operator", "<>"],
["string", ["\"\""]],
["comment", "; Omit next instruction if $Div is null"],
["instruction", "ADC"],
["variable", "$Div"],
["punctuation", ","],
["variable", "$Div"],
["punctuation", ","],
["variable", "$Div"],
["comment", "; Double $Div"],
["directive", "ENDIF"],
["instruction", "MOV"],
["variable", "$Temp"],
["punctuation", ","],
["variable", "$Temp"],
["punctuation", ","],
" LSR ",
["operator", "#"],
["number", "1"],
["comment", "; Halve $Temp,"],
["instruction", "CMP"],
["variable", "$Temp"],
["punctuation", ","],
["variable", "$Bot"],
["comment", "; and loop until"],
["instruction", "BHS"],
["operator", "%"],
"b91 ",
["comment", "; less than divisor"],
["directive", "MEND"]
]