Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
Yeshvanth Muniraj
Published

Demystifying the Disassembly on ARM

A deep dive into the ARMv7-M Architecture Instruction Set

IntermediateProtip30 minutes2,832
Demystifying the Disassembly on ARM

Things used in this project

Hardware components

STMicroelectronics STM32F429 Discovery Board
×1

Story

Read more

Code

Blink LED

Assembly x86
Blink the On Board LED of STM32F429 Discovery
	AREA _code, CODE
		ENTRY
		EXPORT __main
			
__main
	; Base Address of RCC Register
	MOVW  r0, #0x3800
	MOVT  r0, #0x4002
	; RCC_CR - set HSE External & wait
	LDR   r1, [r0]
	ORR   r1, r1, #0x10000
	STR   r1, [r0]
l1  
  LDR   r1, [r0] 
	LSLS  r1, r1, #14
	BPL   l1 ; wait till ready flag
	LDR   r1, [r0, #0x40] ; Power Enable Clock
	ORR   r1, r1, #0x10000000
	STR   r1, [r0, #0x40] 
	MOVW  r1, #0x7000 
	MOVT  r1, #0x4000
	LDR   r2, [r1]
	ORR   r2, r2, #0xC000
	STR   r2, [r1] ; Power Enable Voltage
	MOVW  r1, #0x705
	STR   r1, [r0, #0x400] ; Configure Flash
	LDR   r1, [r0, #0x08] ; Configure APB1 & APB2 prescalar
	ORR   r1, r1, #0x9400
	STR   r1, [r0, #0x08] 
	; Configure main PLL
	MOVW  r1, #0x2D04
	MOVT  r1, #0x40
	STR   r1, [r0, #0x04] 
    ; Enable PLL and wait
	LDR   r1, [r0]
	ORR   r1, r1, #0x1000000
	STR   r1, [r0]
l2  
  LDR   r1, [r0] 
	LSLS  r1, r1, #6
	BPL   l2 ; wait till ready flag
	; Select SW PLL in RCC CFGR as Sys Clock
	LDR   r1, [r0, #0x08]
	ORR   r1, r1, #0x02
	STR   r1, [r0, #0x08]
	; wait for it to be ready
l3  
  LDR   r1, [r0, #0x08]
	AND   r1, r1, #0x0C
	CMP   r1, #0x08
	BNE   l3
	;Timer
	LDR   r1, [r0, #0x40] ; Enable Timer 6 Clock
	ORR   r1, r1, #0x10
	STR   r1, [r0, #0x40] 
	MOVW  r1, #0x1000
	MOVT  r1, #0x4000
	MOVW  r2, #0x2327
	STR   r2, [r1, #0x28] ; prescale count
	MOVW  r2, #0xFFFF
	STR   r2, [r1, #0x2C] ; ARR auto reload
	LDR   r2, [r1]
	ORR   r2, r2, #0x01   ; enable counter
	STR   r2, [r1]
l4	
  LDR   r2, [r1, #0x10] ; wait till the timer is ON
	LSLS  r2, r2, #31
	BEQ   l4
	; Configure the GPIOG (PG13 on STM32 Discovery)
	LDR   r3, [r0, #0x30] 
	ORR   r3, r3, #0x40
	STR   r3, [r0, #0x30]
	MOVW  r2, #0x1800
	MOVT  r2, #0x4002
	LDR   r0, [r2]
	ORR   r0, r0, #0x4000000
	STR   r0, [r2]
	LDR   r0, [r2, #0x04]
	BIC   r0, r0, #0x2000
	STR   r0, [r2, #0x04]
	LDR   r0, [r2, #0x08]
	ORR   r0, r0, #0x8000000
	STR   r0, [r2, #0x08]
	LDR   r0, [r2, #0x0C]
	BIC   r0, r0, #0xC000000
	STR   r0, [r2, #0x0C]
	MOV   r12, #0x00
	MOVW  r3, #0x9C4
	ADD   r2, #0x18
	ADD   r1, #0x24
; blink starts	(Infinite Loop l5)
l5	
  LDR   r0, [r2]
	ORR   r0, r0, #0x2000 ; Set the GPIO (LED ON)
	STR   r0, [r2]
	STR   r12, [r1]
; Wait till the timer counter is less than specified value
l6	
  LDR   r0, [r1]
	CMP   r0, r3
	BCC   l6
	LDR   r0, [r2]
	ORR   r0, r0, #0x20000000 ; Clear the GPIO (LED OFF)
	STR   r0, [r2]
	STR   r12, [r1]
; Wait till the timer counter is less than specified value
l7
  LDR   r0, [r1]
  CMP   r0, r3
	BCC   l7	
    B     l5	
stop	B stop

	END

Credits

Yeshvanth Muniraj

Yeshvanth Muniraj

20 projects β€’ 35 followers
Hands-on experience in Embedded Systems and IoT. Good knowledge of FPGAs and Microcontrollers.

Comments