Search code examples
assemblyavratmega16

out of program memory in assembly


i write a program for ATmega32 to get 8-bit number and show in 7segment but when i simulate it in Proteus it shows me that it is out of program memory what should i do exactly?

.INCLUDE "M32DEF.INC"
.ORG $00
//data to save in program memory
.DB $FC,$30,$6E,$7A,$B2,$DA,$DE,$70,$FE,$FA
.ORG $08
LDI R16,$01
//Statements

Solution

  • The .ORG directives don't look right. The processor starts executing instructions at address 0, but you have placed data there. As well, there are 10 bytes of data, but only 8 bytes to place them in. I'm not sure what the data is for, as you didn't give it a label. Is it supposed to be instructions? Is the digits for an LCD display?

    It would be helpful if you added some comments to your code to describe what your program is trying to do. I can see the part setting up the stack pointer and setting the port directions, but I don't want to try to analyze the loops. Just tell us what you mean to do.

    As a start, you can try to change around the .ORG locations. Often, a program will have a part labelled "main:", with the first instruction at .ORG $0 to be a jump to main. This way you can place data at the top of the program, say at .ORG $08 so that it is easy to find in the code, but does not get executed by mistake.

    .INCLUDE "M32DEF.INC"
    .ORG $00
    jmp main
    
    .ORG $08
    digits: .DB $FC,$30,$6E,$7A,$B2,$DA,$DE,$70,$FE,$FA
    
    main:
    LDI R16,$01 ; set stack pointer
    OUT SPH,R16
    LDI R16,$00
    OUT SPL,R16
    
    and so on