FlexScan Introduction - Lesson 2

by Oliver Scholz

Debugging aids, Part I: Dumping memory

Unless you have a logic analyzer or in circuit emulator, you'll know that writing embedded code without those expensive tools is a tedious task. ScanOS offers some functions that make tracing bugs a little easier. You will often want to see the contents of some memory to verify if your code is doing what it should. If you are writing scantool code (which is why you probably have build a FlexScan in the first place), you will undoubtedly want to view the contents of some data buffers at some point.

Well, the HexDump function will let you do just that. It can handle all kinds of memory, be it internal RAM, internal EEPROM (if equipped) and external EPROM. Since all memories together are less than 64K, all memories have been mapped into a linear address space.

MAIN:	MOV	DPTR,#08000H		;Dump the first four bytes of user EPROM
	LCALL	HEXDUMP			;This call prints address and contents on the LCD and increments DPTR
	LCALL	CRLF			;Helper routine to print CR and LF (not listed here)

	MOV	A,#200			;Wait for 200*10ms = 2 seconds
	LCALL	DELAY			;just to demonstrate this function as well

	LCALL	HEXDUMP			;This call dumps the next four bytes (from $8004-$8007)

	LCALL	INPUT			;Wait for the user to press a key
	LCALL	CLS			;Clear the screen

	MOV	DPTR,#054H		;Dumps four bytes of internal RAM from $54 to $57
	LCALL	HEXDUMP
	...


Debugging aids, Part II: Single Stepping

Another feature that can prove very valuable is the ability to single step through your code. To avoid stepping through the entire code you have to enable and disable this feature through function calls to ScanOS. Additionally, you have to connect a pushbutton type switch (normally closed) between the ALDL input and ground. If the single step feature is enabled, the program will execute one instruction for each time the button is pushed until the feature is switched off again.

You will be able to examine the contents of ACC and BCC, the PC, SP and the PSW register. There is no space for the disassembly, but with the listing for reference, this is a useful feature.

Here is the sample code:

MAIN:
        LCALL   STARTSINGLESTEP	;Start singlestepping after this call returns

	MOV	A,#0C5H		;Fill A with some value
        MOV     DPTR,#0ABCDH	;DPTR too
        MOV     A,#012H		;Fill A with some other value
        MOV     BCC,#034H	;BCC too
        ADD     A,#0FFH  	;Decrement A by one
      
        LCALL   TEST		;Step into a subroutine

        LCALL   STOPSINGLESTEP	;Stop debugging
LOOP:	SJMP	LOOP		;loop forever

TEST:	ADD	A,#3		;increment A by 3
	RET			;return


Back to lesson 1 Click here to go to lesson 3

There have been visitors to this site since May 31, 2000.