配置:GPB5~GPB8 连接4个led 低电平点亮,RAM1起始地址为0x30000000
启动代码S3C2440.s(由RealView-MDK自动生成)
用户程序Main.s:
rGPBCON EQU 0x56000010;//定义端口
rGPBDAT EQU 0x56000014;
rGPBUP EQU 0x56000018;
;导出符号__main
;连接到启动代码
EXPORT __main
;__main函数 相应于C语言的main()函数
AREA __main,CODE,READONLY
ENTRY ;//程序入口点
;Configures the pins of port B
;//设置GPB5~GPB8输出端口
ldr r0,=rGPBCON
ldr r1,=0x55<<10
str r1,[r0]
;GPBUP :Pull-up disable register for port B
;0: The pull up function attached to the corresponding port pin is enabled.
;1: The pull up function is disabled.
;//设置GPBUP为禁止 设置为上拉电阻
ldr r0,=rGPBUP
ldr r1,=0xffff
str r1,[r0]
;装载GPB数据寄存器的地址
ldr r2,=rGPBDAT
ledloop
ldr r1,=~(0x01<<5);//设置GPB5输出灯亮
str r1,[r2];
bl delay;//调用延时子程序
ldr r1,=~(0x03<<5);//设置GPB5GPB6输出低电平,灯亮
str r1,[r2];
bl delay;
ldr r1,=~(0x07<<5);//设置GPB5~7输出灯亮
str r1,[r2];
bl delay;
ldr r1,=~(0x0f<<5);//设置GPB5~8输出灯亮
str r1,[r2];
bl delay;
ldr r1,=~(0x00<<5);//设置全灭
;The LDR Rd,=const pseudo-instruction can construct any 32-bit numeric constant in a single instruction
;generates an LDR instruction with a program-relative address that reads the constant from the literal pool
str r1,[r2]
;STR{cond} Rd, [Rn]
;Rn is used as address value.
;STR{cond} Rd, [Rn, offset]
;Rn and offset are added and used as address value.
;STR{cond} Rd, [Rn, offset]!
;Rn and offset are added and used as address value. The new address value is written to Rn.
;STR{cond} Rd, label
;The assembler calculates the PC offset and generates STR{cond} Rd, [R15], offset.
;STR{cond} Rd, [Rn], offset
;Rn is used as address value. After memory transfer, the offset is added to Rn.
;Store register 32-bit words to Memory. The address must be 32-bit word-aligned.
bl delay;
;BL{cond} label
;Copy address of next instruction to R14 and jump to label. The jump distance must be within ±4Mb of the current instruction.
;Note that this mnemonic is generated as two 16-bit Thumb instructions.
b ledloop
;B{cond} label
;The jump distance must be within -252 to +258 bytes for conditional and ±2 KBytes for unconditional branch.
;不影响标志位
delay
;延时子函数
ldr r3,=0x10000
;The LDR Rd,=const pseudo-instruction can construct any 32-bit numeric constant in a single instruction
;generates an LDR instruction with a program-relative address that reads the constant from the literal pool
delay1
sub r3,r3,#1
cmp r3,#0x0
;CMP {cond} Rn, Op2
;subtracts the value of Op2 from the value in Rn (equals to the SUBS instruction with a discarded result).
;This instruction updates the condition flags, but do not place a result in a register.
;N, Z, C and V flags are updated.
bne delay1
;B{cond} label
;The jump distance must be within -252 to +258 bytes for conditional and ±2 KBytes for unconditional branch.
;不影响标志位
BX LR
;mov pc,lr;//返回主程序
;LR 即连接寄存器 R14
END