Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
881 views
in Technique[技术] by (71.8m points)

assembly - How do 8-bit and 16-bit processors access more RAM with two registers?

Something that has always confused me is how 8-bit computers access more than 256 bytes of RAM. I know that it must use two registers, but can any one show me an example of what this would look like in assembly code?

Like:

mov a, [x]   ???
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Let's imagine we have LOWER and HIGHER 8bit half of the address in registers L and H. For example, we want to read byte from address 32770 dec = 8002 hex.

mov l, 02h  ;lower byte of address
mov h, 80h  ;higher byte of address
mov a, [hl] ;a <-- [h*256 + l]

Many addressing modes exist in CPUs. So we can have a different example, e.g. with just a single register and an immediate address:

mov h, 80h
mov a, [2]  ;a <-- [h*256 + immediate]

It always depends on a particular CPU architecture. For example Zilog Z80 is called 8-bit CPU but it also contains many 16-bit instructions. You can do indexed addressing on it like this:

mov ix, 8002h  ;base address of an array
mov a,[ix+20]  ;a <-- [ix + 20] i.e. read a byte from an array like ix[20] in C

Note: Those old 8-bit CPU's use an 8-bit accumulator, i.e. they can compute math and other arithmetic stuff only in an 8-bit register, so they are 8-bit on a software computation level. And their memory accessing unit is 8-bit, i.e. it can read or write just a single byte of memory at a time, so they are 8-bit on hardware level too. Those 16-bit instructions are slow, they actually do a pair of 8-bit operations in succession.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...