[Principle of Microcomputer] Zero-based five minutes to teach you to understand DUP memory allocation calculation

This article uses three sample questions to take you five minutes to understand the DUP memory allocation calculation

Basic concept explanation

When defining data, we will encounter the following instructions. To start calculating, we need to figure out how many bytes they represent:

  1. Define the number of bytes :
Keyword abbreviation Alias Number of defined bytes
define byte DB BYTE 1
define word DW WORD 2
define double word DD DWORD 4
  1. mDUP(x1, x2, x3...xn) :
    Take m*none space, and assign initial values ​​x1, x2, x3...xn to each m space in turn.

example

After the following statements are assembled, what is the number of bytes in the storage unit allocated for the variable BUF?

BUF DW 10H DUP(3 DUP(2,10H),3,5) 
BUF DWORD 10H DUP(3 DUP(2,5),3,4,5)
  1. 2*16*(3*2+1+1) = 256 = 100H
    Analysis: DW define word defines each space as 2a byte, a total of 10H= 16 spaces. After that, each space was allocated again: a 3small space + 1 3+ 1 space 5. The two bytes allocated in each small space are 2and10H
  2. 4*16*(3*2+1+1+1) = 576 = 240H
    Analysis: DWORD define double word defines each space as 4a byte, a total of 10H= 16 spaces. After that, each space was allocated: a 3small space+1 3+1 4+1+1 5. The two bytes allocated in each small space are 2and5

exercise

BUF DW 10H DUP(3 DUP (2,?), 1, 2 DUP(?), 100

What is the number of bytes of the memory space allocated for the variable BUF?

answer

2 * 16 * (32 + 1 + 21 + 1)= 320 = 140H

Pay attention to the conversion of decimal and hexadecimal

During the calculation process, it is best to convert to decimal calculation and then convert the result back to hexadecimal (if necessary)

Guess you like

Origin blog.csdn.net/weixin_44559752/article/details/106756907