⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 exa7.html

📁 关于ARM汇编的非常好的教程
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<h2>Callbacks</h2>The next step is to seperate the switching off from the switching on. The way we shall dothis is to set up a callback.<p>First, change:<pre>    \ Invert    EOR     R1, R1, #2             ; Bit 1 is Scroll Lock, invert it.</pre>to:<pre>    \ Switch on Scroll Lock    ORR     R1, R1, #2             ; Bit 1 is Scroll Lock, set it.</pre>Now after the &quot;<code>\ Update keyboard LEDs</code>&quot; code, add:<pre>    \ Set up timed callback to switch LED off again    MOV    R0, #20                 ; After 20 centiseconds    ADR    R1, callback_handler    MOV    R2, #0    SWI    &quot;OS_CallAfter&quot;</pre>Then at the bottom add:<pre>  .callback_handler    \ This isn't quite interrupt-level code, but getting close!    STMFD   R13!, {R0 - R2, R14}    \ Unset the keyboard LED    \ Read    MOV     R0, #202    MOV     R1, #0    MOV     R2, #255    SWI     &quot;OS_Byte&quot;    \ Switch off Scroll Lock    AND     R1, R1, #253           ; 253 preserves every bit EXCEPT bit 2.    \ Write    MOV     R2, #0    SWI     &quot;OS_Byte&quot;    \ Update LEDs    MOV     R0, #118    SWI     &quot;OS_Byte&quot;    \ Remove callback    ADR     R0, callback_handler    MOV     R1, #0    SWI     &quot;OS_RemoveTickerEvent&quot;    \ Return    LDMFD   R13!, {R0 - R2, PC}</pre>Assemble and run this.<br>Something is wrong, isn't it?<p>Go to the part where the timed callback is set up, and try for a shorter delay. Drasticallyshorter, like 2cs.<p>&nbsp;<p><h2>To wrap up...</h2>Well, I did intend to check if a callback was pending in the vector handler, but now I don'tthink I'll bother as this module now does exactly what I want.<p>All in an hour's work! :-)<p>&nbsp;<p>Please be aware that this utility, logically, will add a delay to file operations. I havemeasured the delay to be something in the region of 28%. I tried some optimisations suchas:<pre>    LDMFD  R13!, {R0-R2, PC}^</pre>rather than:<pre>    LDMFD  R13!, {R0-R2, R14}    MOVS   PC, R14</pre>but it made a negligible difference.<br>This is really a case of deciding if the delay introduced outweighs the benefit of having ablinking HD light. For me, it does. For you? Your choice...<br><font color="red">The <code>LDMFD R13!, { ... }^</code> is not 32-bit friendly.</font><p>&nbsp;<p><h2>Full listing of the module</h2>This is a full listing of the source required to create this module. It includes someadditional help... <font color="red">Oh, and it isn't 32-bit friendly.</font><p>You will need to set <code>&lt;DiscAcc$Dir&gt;</code>, or simply edit the code...<p><pre>REM &gt;SourceCodeREMREM DiscAccess module sourceREMREM Version 0.01REMREM Assembler programming example 7REM Downloaded from: http://www.heyrick.co.uk/assembler/:ON ERROR PRINT REPORT$+&quot; at &quot;+STR$(ERL/10) : END:DIM code% 2048:FOR pass% = 4 TO 6 STEP 2P%=0O%=code%[ OPT pass%    EQUD    0                      ; Start-up code    EQUD    initialise             ; Initialisation    EQUD    finalise               ; Finalisation    EQUD    0                      ; Service call handler    EQUD    module_title           ; Module title    EQUD    module_help            ; Module help    EQUD    help_table             ; Help and command decoding table    EQUD    0                      ; SWI chunk base number    EQUD    0                      ; SWI handling code    EQUD    0                      ; SWI decoding code    EQUD    0                      ; SWI decoding code  .module_title    EQUS    &quot;DiscAccess&quot;    EQUB    0    ALIGN  .module_help    EQUS    &quot;DiscAccess&quot;+CHR$(9)+&quot;0.01 (14 Oct 2000)&quot;    EQUB    0    ALIGN  .help_table    EQUS    &quot;DiscAccess&quot;           ; Keyword string    EQUB    0    ALIGN    EQUD    0                      ; Pointer to code (there is no code!)    EQUD    0                      ; Parameter information (no parameters)    EQUD    0                      ; Pointer to syntax string    EQUD    discaccess_help        ; Pointer to help string    EQUD    0                      ; End of command table  .discaccess_help    ; Only put a linefeed where one is required, else put a trailing space.    ; RISC OS will wrap the text as appropriate to fit the dimensions in use...    EQUS    &quot;DiscAccess is a simple little module that blinks your Scroll Lock &quot;    EQUS    &quot;key when files are accessed.&quot;+CHR$13    EQUS    &quot;It is designed to take the place of a dedicated HD indicator on &quot;    EQUS    &quot;machines that don't have such a thing (ie, the A3000); so you &quot;    EQUS    &quot;probably won't need it on a RiscPC!&quot;+CHR$13+CHR$13    EQUS    &quot;DiscAccess was written by Richard Murray as a tutorial for the &quot;    EQUS    CHR$34+&quot;Teach yourself ARM assembler&quot;+CHR$34+&quot;, which is freely &quot;    EQUS    &quot;available at:&quot;+CHR$13    EQUS    CHR$160+CHR$160+&quot;http://www.heyrick.co.uk/assembler/&quot;+CHR$13    EQUS    CHR$160+CHR$160+&quot;(this is example seven!)&quot;+CHR$13+CHR$13    EQUB    0    ALIGN    ; The hard spaces (CHR$160) force a small indent.  .initialise    STMFD   R13!, {R14}    \ Attach vector handler to the six vectors that deal with file ops.    MOV     R0, #&amp;8                ; FileV    ADR     R1, vector_handler    MOV     R2, #0    SWI     &quot;OS_AddToVector&quot;    MOV     R0, #&amp;9                ; ArgsV    ADR     R1, vector_handler    MOV     R2, #0    SWI     &quot;OS_AddToVector&quot;    MOV     R0, #&amp;A                ; BGetV    ADR     R1, vector_handler    MOV     R2, #0    SWI     &quot;OS_AddToVector&quot;    MOV     R0, #&amp;B                ; BPutV    ADR     R1, vector_handler    MOV     R2, #0    SWI     &quot;OS_AddToVector&quot;    MOV     R0, #&amp;C                ; GBPBV    ADR     R1, vector_handler    MOV     R2, #0    SWI     &quot;OS_AddToVector&quot;    MOV     R0, #&amp;D                ; FindV    ADR     R1, vector_handler    MOV     R2, #0    SWI     &quot;OS_AddToVector&quot;    LDMFD   R13!, {PC}  .finalise    STMFD   R13!, {R14}    MOV     R0, #&amp;8                ; FileV    ADR     R1, vector_handler    MOV     R2, #0    SWI     &quot;OS_Release&quot;    MOV     R0, #&amp;9                ; ArgsV    ADR     R1, vector_handler    MOV     R2, #0    SWI     &quot;OS_Release&quot;    MOV     R0, #&amp;A                ; BGetV    ADR     R1, vector_handler    MOV     R2, #0    SWI     &quot;OS_Release&quot;    MOV     R0, #&amp;B                ; BPutV    ADR     R1, vector_handler    MOV     R2, #0    SWI     &quot;OS_Release&quot;    MOV     R0, #&amp;C                ; GBPBV    ADR     R1, vector_handler    MOV     R2, #0    SWI     &quot;OS_Release&quot;    MOV     R0, #&amp;D                ; FindV    ADR     R1, vector_handler    MOV     R2, #0    SWI     &quot;OS_Release&quot;    LDMFD   R13!, {PC}  .vector_handler    \ IMPORTANT! WE ARE IN SVC MODE!    STMFD   R13!, {R0 - R2, R14}   ; Preserve registers    \ Read    MOV     R0, #202               ; Update keyboard status, but using EOR    MOV     R1, #0                 ; mask 0 and AND mask 255, we can read    MOV     R2, #255               ; the state...    SWI     &quot;OS_Byte&quot;              ; New value in R1    \ Switch on Scroll Lock    ORR     R1, R1, #2             ; Bit 1 is Scroll Lock, set it.    \ Write    MOV     R2, #0                 ; AND mask is 0, so EOR value is used.    SWI     &quot;OS_Byte&quot;    \ Update keyboard LEDs    MOV     R0, #118    SWI     &quot;OS_Byte&quot;    \ Set up timed callback to switch LED off again    MOV    R0, #2                  ; After 2 centiseconds    ADR    R1, callback_handler    MOV    R2, #0    SWI    &quot;OS_CallAfter&quot;    LDMFD   R13!, {R0 - R2, R14}   ; Restore registers    MOVS    PC, R14                ; Pass this one on  .callback_handler    \ This isn't quite interrupt-level code, but getting close!    STMFD   R13!, {R0 - R2, R14}    \ Unset the keyboard LED    \ Read    MOV     R0, #202    MOV     R1, #0    MOV     R2, #255    SWI     &quot;OS_Byte&quot;    \ Switch off Scroll Lock    AND     R1, R1, #253           ; 253 preserves every bit EXCEPT bit 2.    \ Write    MOV     R2, #0    SWI     &quot;OS_Byte&quot;    \ Update LEDs    MOV     R0, #118    SWI     &quot;OS_Byte&quot;    \ Remove callback    ADR     R0, callback_handler    MOV     R1, #0    SWI     &quot;OS_RemoveTickerEvent&quot;    \ Return    LDMFD   R13!, {R0 - R2, PC}  .stuff_at_the_end    EQUB    10    EQUB    10    EQUS    &quot;DiscAccess module 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -