Microcontroller › 8051 › How to tell SDCC the location of code memory
- This topic has 0 replies, 1 voice, and was last updated 9 years, 5 months ago by Ashok Das.
-
AuthorPosts
-
April 25, 2015 at 2:50 pm #3646Ashok DasParticipant
Hi all,
This problem may be very simple for c programmers but for a assembly guy like me its very critical. I have a 89S51 board, which have a external static RAM located at 0x2000. I use this for both code and data memory. While assembling any program, I use ORG directive to tell assembler to start the code from 0x2000. This works fine. Now I moved to C (SDCC as no way I can afford KEIL). Now how to tell SDCC to compile the code from address 0x2000 ? I could not find any straight answer. SDCC manual has two command line options:
–code-loc <Value> The start location of the code segment, default value 0. Note when this option is used the
interrupt vector table is also relocated to the given address. The value entered can be in Hexadecimal
or Decimal format, e.g.: –code-loc 0x8000 or –code-loc 32768.and
–xram-loc <Value> The start location of the external ram, default value is 0. The value entered can be in Hexadecimal
or Decimal format, e.g.: –xram-loc 0x8000 or –xram-loc 32768.I used these like
sdcc –code-loc 0x2000 –xram-loc 0x2000 serial_101.c
The program serial_101.c compiles successfully, but starting location is 0x0000 as i observed in generated ASM file. I am using Windows7 64 and WindowsXP 32. I am posting my c file and generated ASM file
#include <mcs51/8051.h>
#include <stdio.h>
#include <ctype.h>
char getchar (void) {
char c;
while (!RI); /* wait to receive */
c = SBUF; /* receive from serial */
RI = 0;
return c;
}
void putchar (char c) {
while (!TI); /* wait end of last transmission */
TI = 0;
SBUF = c; /* transmit to serial */
}
void UART_Init() {
SCON = 0x50; /* configure serial */
TMOD = 0x20; /* configure timer */
TH1 = 0xE6; /* baud rate 1200 */
TL1 = 0xE6; /* baud rate 1200 */
TR1 = 1; /* enable timer */
TI = 1; /* enable transmitting */
RI = 0; /* waiting to receive */
}
void main() {
UART_Init();
for(; {
char c;
c = getchar();
c = toupper(c);
putchar(c);
}
}And the ASM file
;
; File Created by SDCC : free open source ANSI-C Compiler
; Version 3.4.0 #8981 (Apr 5 2014) (MINGW32)
; This file was generated Sat Apr 25 17:58:06 2015
;
.module serial_101
.optsdcc -mmcs51 –model-small
;
; Public variables in this module
;
.globl _main
.globl _UART_Init
.globl _toupper
.globl _CY
.globl _AC
.globl _F0
.globl _RS1
.globl _RS0
.globl _OV
.globl _F1
.globl _P
.globl _PS
.globl _PT1
.globl _PX1
.globl _PT0
.globl _PX0
.globl _RD
.globl _WR
.globl _T1
.globl _T0
.globl _INT1
.globl _INT0
.globl _TXD
.globl _RXD
.globl _P3_7
.globl _P3_6
.globl _P3_5
.globl _P3_4
.globl _P3_3
.globl _P3_2
.globl _P3_1
.globl _P3_0
.globl _EA
.globl _ES
.globl _ET1
.globl _EX1
.globl _ET0
.globl _EX0
.globl _P2_7
.globl _P2_6
.globl _P2_5
.globl _P2_4
.globl _P2_3
.globl _P2_2
.globl _P2_1
.globl _P2_0
.globl _SM0
.globl _SM1
.globl _SM2
.globl _REN
.globl _TB8
.globl _RB8
.globl _TI
.globl _RI
.globl _P1_7
.globl _P1_6
.globl _P1_5
.globl _P1_4
.globl _P1_3
.globl _P1_2
.globl _P1_1
.globl _P1_0
.globl _TF1
.globl _TR1
.globl _TF0
.globl _TR0
.globl _IE1
.globl _IT1
.globl _IE0
.globl _IT0
.globl _P0_7
.globl _P0_6
.globl _P0_5
.globl _P0_4
.globl _P0_3
.globl _P0_2
.globl _P0_1
.globl _P0_0
.globl _B
.globl _ACC
.globl _PSW
.globl _IP
.globl _P3
.globl _IE
.globl _P2
.globl _SBUF
.globl _SCON
.globl _P1
.globl _TH1
.globl _TH0
.globl _TL1
.globl _TL0
.globl _TMOD
.globl _TCON
.globl _PCON
.globl _DPH
.globl _DPL
.globl _SP
.globl _P0
.globl _getchar
.globl _putchar
;
; special function registers
;
.area RSEG (ABS,DATA)
.org 0x0000
_P0 = 0x0080
_SP = 0x0081
_DPL = 0x0082
_DPH = 0x0083
_PCON = 0x0087
_TCON = 0x0088
_TMOD = 0x0089
_TL0 = 0x008a
_TL1 = 0x008b
_TH0 = 0x008c
_TH1 = 0x008d
_P1 = 0x0090
_SCON = 0x0098
_SBUF = 0x0099
_P2 = 0x00a0
_IE = 0x00a8
_P3 = 0x00b0
_IP = 0x00b8
_PSW = 0x00d0
_ACC = 0x00e0
_B = 0x00f0
;
; special function bits
;
.area RSEG (ABS,DATA)
.org 0x0000
_P0_0 = 0x0080
_P0_1 = 0x0081
_P0_2 = 0x0082
_P0_3 = 0x0083
_P0_4 = 0x0084
_P0_5 = 0x0085
_P0_6 = 0x0086
_P0_7 = 0x0087
_IT0 = 0x0088
_IE0 = 0x0089
_IT1 = 0x008a
_IE1 = 0x008b
_TR0 = 0x008c
_TF0 = 0x008d
_TR1 = 0x008e
_TF1 = 0x008f
_P1_0 = 0x0090
_P1_1 = 0x0091
_P1_2 = 0x0092
_P1_3 = 0x0093
_P1_4 = 0x0094
_P1_5 = 0x0095
_P1_6 = 0x0096
_P1_7 = 0x0097
_RI = 0x0098
_TI = 0x0099
_RB8 = 0x009a
_TB8 = 0x009b
_REN = 0x009c
_SM2 = 0x009d
_SM1 = 0x009e
_SM0 = 0x009f
_P2_0 = 0x00a0
_P2_1 = 0x00a1
_P2_2 = 0x00a2
_P2_3 = 0x00a3
_P2_4 = 0x00a4
_P2_5 = 0x00a5
_P2_6 = 0x00a6
_P2_7 = 0x00a7
_EX0 = 0x00a8
_ET0 = 0x00a9
_EX1 = 0x00aa
_ET1 = 0x00ab
_ES = 0x00ac
_EA = 0x00af
_P3_0 = 0x00b0
_P3_1 = 0x00b1
_P3_2 = 0x00b2
_P3_3 = 0x00b3
_P3_4 = 0x00b4
_P3_5 = 0x00b5
_P3_6 = 0x00b6
_P3_7 = 0x00b7
_RXD = 0x00b0
_TXD = 0x00b1
_INT0 = 0x00b2
_INT1 = 0x00b3
_T0 = 0x00b4
_T1 = 0x00b5
_WR = 0x00b6
_RD = 0x00b7
_PX0 = 0x00b8
_PT0 = 0x00b9
_PX1 = 0x00ba
_PT1 = 0x00bb
_PS = 0x00bc
_P = 0x00d0
_F1 = 0x00d1
_OV = 0x00d2
_RS0 = 0x00d3
_RS1 = 0x00d4
_F0 = 0x00d5
_AC = 0x00d6
_CY = 0x00d7
;
; overlayable register banks
;
.area REG_BANK_0 (REL,OVR,DATA)
.ds 8
;
; internal ram data
;
.area DSEG (DATA)
;
; overlayable items in internal ram
;
.area OSEG (OVR,DATA)
.area OSEG (OVR,DATA)
;
; Stack segment in internal ram
;
.area SSEG
__start__stack:
.ds 1;
; indirectly addressable internal ram data
;
.area ISEG (DATA)
;
; absolute internal ram data
;
.area IABS (ABS,DATA)
.area IABS (ABS,DATA)
;
; bit data
;
.area BSEG (BIT)
;
; paged external ram data
;
.area PSEG (PAG,XDATA)
;
; external ram data
;
.area XSEG (XDATA)
;
; absolute external ram data
;
.area XABS (ABS,XDATA)
;
; external initialized ram data
;
.area XISEG (XDATA)
.area HOME (CODE)
.area GSINIT0 (CODE)
.area GSINIT1 (CODE)
.area GSINIT2 (CODE)
.area GSINIT3 (CODE)
.area GSINIT4 (CODE)
.area GSINIT5 (CODE)
.area GSINIT (CODE)
.area GSFINAL (CODE)
.area CSEG (CODE)
;
; interrupt vector
;
.area HOME (CODE)
__interrupt_vect:
ljmp __sdcc_gsinit_startup
;
; global & static initialisations
;
.area HOME (CODE)
.area GSINIT (CODE)
.area GSFINAL (CODE)
.area GSINIT (CODE)
.globl __sdcc_gsinit_startup
.globl __sdcc_program_startup
.globl __start__stack
.globl __mcs51_genXINIT
.globl __mcs51_genXRAMCLEAR
.globl __mcs51_genRAMCLEAR
.area GSFINAL (CODE)
ljmp __sdcc_program_startup
;
; Home
;
.area HOME (CODE)
.area HOME (CODE)
__sdcc_program_startup:
ljmp _main
; return from main will return to caller
;
; code
;
.area CSEG (CODE)
;
;Allocation info for local variables in function 'getchar'
;
;c Allocated to registers
;
; serial_101.c:5: char getchar (void) {
;
; function getchar
;
_getchar:
ar7 = 0x07
ar6 = 0x06
ar5 = 0x05
ar4 = 0x04
ar3 = 0x03
ar2 = 0x02
ar1 = 0x01
ar0 = 0x00
; serial_101.c:7: while (!RI); /* wait to receive */
00101$:
jnb _RI,00101$
; serial_101.c:8: c = SBUF; /* receive from serial */
mov dpl,_SBUF
; serial_101.c:9: RI = 0;
clr _RI
; serial_101.c:10: return c;
ret
;
;Allocation info for local variables in function 'putchar'
;
;c Allocated to registers r7
;
; serial_101.c:13: void putchar (char c) {
;
; function putchar
;
_putchar:
mov r7,dpl
; serial_101.c:14: while (!TI); /* wait end of last transmission */
00101$:
; serial_101.c:15: TI = 0;
jbc _TI,00112$
sjmp 00101$
00112$:
; serial_101.c:16: SBUF = c; /* transmit to serial */
mov _SBUF,r7
ret
;
;Allocation info for local variables in function 'UART_Init'
;
; serial_101.c:19: void UART_Init() {
;
; function UART_Init
;
_UART_Init:
; serial_101.c:20: SCON = 0x50; /* configure serial */
mov _SCON,#0x50
; serial_101.c:21: TMOD = 0x20; /* configure timer */
mov _TMOD,#0x20
; serial_101.c:22: TH1 = 0xE6; /* baud rate 1200 */
mov _TH1,#0xE6
; serial_101.c:23: TL1 = 0xE6; /* baud rate 1200 */
mov _TL1,#0xE6
; serial_101.c:24: TR1 = 1; /* enable timer */
setb _TR1
; serial_101.c:25: TI = 1; /* enable transmitting */
setb _TI
; serial_101.c:26: RI = 0; /* waiting to receive */
clr _RI
ret
;
;Allocation info for local variables in function 'main'
;
;c Allocated to registers r7
;
; serial_101.c:29: void main() {
;
; function main
;
_main:
; serial_101.c:30: UART_Init();
lcall _UART_Init
00102$:
; serial_101.c:33: c = getchar();
lcall _getchar
; serial_101.c:34: c = toupper(c);
mov a,dpl
mov r5,a
rlc a
subb a,acc
mov r6,a
mov dpl,r5
mov dph,r6
lcall _toupper
mov r5,dpl
mov ar7,r5
; serial_101.c:35: putchar(c);
mov dpl,r7
lcall _putchar
sjmp 00102$
.area CSEG (CODE)
.area CONST (CODE)
.area XINIT (CODE)
.area CABS (ABS,CODE)
Any suggestion for my simple problem?
Thanks
Ashok
-
AuthorPosts
- You must be logged in to reply to this topic.