What is an unused memory address?

为君一笑 提交于 2019-12-13 04:26:48

问题


Reading this HTML page on Commodore 64 memory allocations because I am interested in old computer hardware, I stumbled across a cell in the table that claims that the memory address is unused. What exactly does this entail? Does this mean that if you wanted to put something in that address you can put whatever you want? Confused, and would appreciate all answers. Thanks.


回答1:


Memory maps should usually specify which programs use this memory. If they say "unused", this means that these specified programs do not use this address. Here you can see it better: https://www.c64-wiki.com/wiki/Zeropage:

Those zeropage addresses are useful and important in programming the C64 - so useful that the internal KERNAL and BASIC system ROMs make use of most of them, leaving only a handful that are completely "safe" for machine language programmers to use for their own purposes, without risking a system crash.

So, the memory map is only valid for KERNAL and BASIC.

Other programs - including yours - may access the unused addresses without risk. If other programs are loaded, you have to find out, which adressses are accesed by them. You may also access other addresses - even if they are used by other programs - if you know exactly what happens then...




回答2:


LT;DR.

It refers to work ram address which are not used by BASIC or KERNAL routines and free for general purpose programming use.

Long Explanation:

The page you are referring is a really good resource but it is too much detailed if you are not familiar with the system itself. I recommend understanding general memory layout before going into such detail.

Below is the general memory map taken from COMPUTE! magazine issue 32

c64 memory map is highly configurable. You can see I/O and ROM areas placed on top of RAM area. In C64 architecture there is always hidden RAM underneath the ROM areas. You can switch off the ROM areas you don't need to reach the RAM underneath and switch back to ROM (or I/O) when required. You can also move screen ram to anywhere you want.

Only the area between $0000-$0400, which is called as work ram, is fixed because this area is used by the operating system (BASIC interpreter and KERNAL routines). If you want to use the memory within work ram without having strange side effects, you must close BASIC or KERNAL ROM.

e.g.: If you close BASIC rom, you can safely use the zero-page addresses from $2 to $90

There are clever solutions though. Like utility tools, assuming you will not use the dataset, resides in datasette buffer ($033C-$03FB) or using screen ram as temporary buffer and effectively filling screen with garbled characters.

I must also remind that the first page of memory (from $0000 to $00FF) is extremely important for 6502 family CPUSs. This area is called as zero-page. Instructions working at zero page takes one less byte in memory and are executed one cycle faster. Additionally Indexed Indirect and Indirect Indexed memory modes are only available in zero-page.

If you need to keep the default memory configuration and still need some zero-page variables you need to find unused address within zero-page. This is the main reason there are called as 'Unused' in the detailed memory map.

Please also note: User written ML programs are conventionally placed in $C000-$D000 which is not touched by BASIC interpreter and called as 'Free Ram'




回答3:


BASIC and KERNAL use most of zero-page (addresses $0000 through $00FF), leaving little for you to use for your own programs. The unused addresses are $0002 and $00FB through $00FE.

Zero-page is special on the 6502 and related CPUs. Consider the instruction:

LDA $1234

This loads the accumulator (one of the registers) with the contents of address $1234. There is a faster version of this instruction for zero-page addresses:

LDA $02

So far, not a big deal, but there are two indirect addressing modes which require zero-page. For example:

LDA ($FB),y

reads the contents of $FB and $FC, treating them as a little-endian 16-bit address, adds the value of the Y register to this 16-bit address, and then loads the accumulator from this address. Note that this uses two adjacent bytes in zero-page. This makes the four unused bytes near the end of zero-page much more useful than the one unused byte at $02.

If you're just starting out, you can make do with just four bytes of zero-page. Later on, you might consider saving and restoring a portion of zero-page used by BASIC. You'll want to avoid the portion used by the KERNAL if you call any KERNAL routines from your program.

If you're programming in BASIC, none of this really matters. You'll probably only use PEEK and POKE to control video, audio, and I/O. You can use BASIC variables and arrays to store your program's data.



来源:https://stackoverflow.com/questions/52781571/what-is-an-unused-memory-address

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!