Problems of defining local and global variables

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Problems of defining local and global variables

跳至解决方案
1,666 次查看
sctang
Contributor I

Hello,

 

I am a beginner of writing application that consists of one main program with subroutines in separate files for HCS08QE.

 

In my test program, I declared a global variable (GlobalVar) in the main program and two local variables (SubRoutineVar1 and SubRoutineVar2).  However, the subroutines cannot see the Global Variable and it cannot be compiled.

 

When I replaced the comment "ADD GlobalVar" by "ADD #05" in the subroutine, the program can be complied, but in the .map file, I found the SR_DataSec Section started at 0x20A3 (which is in the ROM segment, but I want it to be at the direct-page RAM segment).

 

By the way, I have tried to find some information about using CW. Some pdfs mention changing the .prm file, but I got more errors after doing that. I have been reading the pdf  "HC(S)08/RS08 Assembler Manual for Microcontrollers", may I have your advices what infomation (e.g. pdfs) I should read to learn such things.

 

Thanks a lot.

标签 (1)
标记 (1)
0 项奖励
1 解答
830 次查看
CrasyCat
Specialist III

Hello

 

Do not mix variable definition and code in a single section.

 

SR_Test.asm should look as follows:

 

MY_ZEROPAGE: SECTION  SHORT         ; Insert here your data definitionSubRoutineVar1 DS.B 1SubRoutineVar2 DS.B 1MyCode:     SECTIONSR_Test_Function:

 

 

CrasyCat

在原帖中查看解决方案

0 项奖励
6 回复数
830 次查看
bigmac
Specialist III

Hello,

 

You have XDEFed and XREFed your sub-routine name, but you also need to do this with other symbols to be exported from and imported to various files, including the variable symbols.

 

For example, for GlobalVar to be visible from SR_Test.asm file, you would need to export from main.asm (XDEF GlobalVar), and import to SR_Test.asm (XREF GlobalVar).

 

Regards,

Mac

 

0 项奖励
830 次查看
sctang
Contributor I

Thanks, Mac.

It can be complied now. However, when I press F5 to debug it, I found the address of SubRoutineVar1 and SubRoutineVar2 are 0xA3 and 0xA4 respectively. I would expect them following that of GlobalVar (0x80). How can I assign the address of the variables in the subroutine becuase I am writing another application which has more variables and they were assigned to the ROM segment by the assembler.

Thanks.

0 项奖励
830 次查看
CrasyCat
Specialist III

Hello

 

I would recommend you to define GlobalVar, SubRoutineVar1 and SubRoutineVar2 in the same section.

i.e. Use the same SECTION directive prior to SubRoutineVar1 and SubRoutineVar2 definition as the one

you are using for GlobalVar.

 

CrasyCat

0 项奖励
830 次查看
sctang
Contributor I

Hello CrasyCat,

 

Do you mean adding the line "MY_ZEROPAGE: SECTION  SHORT" in the subroutine file "SR_Test.asm" before defining SubRoutineVar1 and SubRoutineVar2 as following?

 

MY_ZEROPAGE: SECTION  SHORT   
SubRoutineVar1 DS.B 1
SubRoutineVar2 DS.B 1

 

However I got the following errors:

L1112: The MY_ZEROPAGE section has segment type CODE (illegal)

and L1934: ELF: Section 'MY_ZEROPAGE' located in a segment with invalid qualifier.

 

I appreciate your helps.  Thanks.

 

 

0 项奖励
831 次查看
CrasyCat
Specialist III

Hello

 

Do not mix variable definition and code in a single section.

 

SR_Test.asm should look as follows:

 

MY_ZEROPAGE: SECTION  SHORT         ; Insert here your data definitionSubRoutineVar1 DS.B 1SubRoutineVar2 DS.B 1MyCode:     SECTIONSR_Test_Function:

 

 

CrasyCat

0 项奖励
830 次查看
sctang
Contributor I

Thanks CrasyCat!

You save the day. I oversaw the code section when I focused on the problem of the variable section.

 

0 项奖励