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

📄 example_asm.txt

📁 这是一篇关于8位RISC CPU设计的文章
💻 TXT
字号:
 ;----------------------------------- ; AN EXAMPLE ASSEMBLER PROGRAM  ;----------------------------------- ;---------------------------------------------- ; define all the constants before using them  ;---------------------------------------------- define off   0x00 define on    0xff define bad   0xaa define good  0x55 define rst_vector  0x1000 define nmi_vector  0x1500 define div0_vector 0x1700 define int3_vector 0x1800  ;-------------------------------------------------------------- ; vector table - (4 bytes per vector, jmpa takes only 3 bytes) ;-------------------------------------------------------------- org 0x0000       ; reset    jmpa al 0x1000 org 0x0004       ; nmi   jmpa al nmi_vector  org 0x0008       ; div 0   jmpa al div0_vector org 0x000c       ; int 3   jmpa al int3_vector  ;----------------------- ; nmi service routine ;----------------------- org nmi_vector   psh  r1   psh  r2   ldi  r1 on    ldi  r2 off   lda  r0 0xfff0   cmp  r1    jmpr eq turn_off   sta  r1 0xfff0   jmpr al s_end  turn_off:   sta  r2 0xfff0 s_end:   pop  r2   pop  r1   ret ;------------------------ ; some xyz subroutine ;------------------------ org 0x3600 some_xyz:   ldi r0 0x23  sta r0 0xffe0  ret   ;----------------------------- ; move_string subroutine ;------------------------------ org 0x4000  move_string:      psh  r1   psh  r4   psh  r5   psh  r6   psh  r7   pmov a2 src_str  ; source string   pmov a3 dst_str  ; destination string   ldi  r1 0x00     ; end of the string loop_moves_sub:   ldr  a2   cmp  r1   jmpr eq end_moves_sub    str  a3    inca a2   inca a3   jmpr al loop_moves_sub end_moves_sub:   pop  r7   pop  r6   pop  r5   pop  r4   pop  r1   ret  ;------------------  ; main program  ;------------------  org rst_vector   ldi r0 0xaa   ldi r1 0xaa    ldi r2 0xff   add r1   cmp r2   jmpa ne error   ldi r1 0x01   ldi r0 0x26   ldi r2 0x27 loop1:   add r1   cmp r2   jmpa ne error   inc r2   jmpr ne loop1   jmps al some_xyz   ldi r0 good   jmpa al finish ;------------------- ; define the data ;------------------- src_str:   dcb "source_string"     dcb 0x00 dst_str:   dcb "destin_string"   dcb 0x00 no_strings_attached:   dcb "this is string one"   dcb "this is string two"   dcb "THIS IS STRING three" other_bytes1:   dcb 0x21 0x34 0x44 0x78 0xff other_bytes2:   dcb 12 255 145 0 table1:    dmem 10          ; allocate 10  bytes and initialized it with 0 table2:   dmem 300(0x11)   ; allocate 300 byes and initialize it with  0x11    dmem 22(02)      ; allocate 22  bytes and initialize it with 02   dmem 0x10(0xff)  ; allocate 16  bytes and initialize it with 0xff   ; back to program  error:   ldi r0 bad finish:   sta r0 0xffff   end  ; not necessary to have a "end" directive. End of file also represents        ; end of program. 

⌨️ 快捷键说明

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