开发者

Meaning of an assembly language statement

There is an assembly language command:

add dl, 48d

What is the exact purpose and meaning of this assembly language statement? When I write the code

mov al, 02
mov dl, al
mov ah, 02
int 21h

it gives output as b. But when I write,

mov al, 02
mov dl, al
add dl, 48d
mov ah, 02
int 21h

it gives 2 as output. What is this statement doing, exact开发者_高级运维ly?


Looks like x86 assembler. This command is adding 48 (48 decimal) to the content of the lower 8 bit of the (E)DX register. See x86 general purpose registers, but for real explanations see the x86 Wikipedia page, section "x86 registers".

On x86, you can access parts of a register. Historically, this was done so that the 8086 (16 bit registers) was as compatible as possible with the 8080 (8 bit registers). That scheme was then extended on the 80286/80386 with 32 bit registers and then again to 64 bit in the AMD x64 mode.

So you can access the whole 32 bit register as EDX (when in protected mode) and the lower 16 bit register as DX. Now this 16 bit part (DX) is further divided into two parts: the upper 8 bit are accessed as DH, the lower 8 bit as DL.

Edit after the question was edited:

Let's explain the cited code from back to front: at the end, interrupt 21hex is called which on IBM PC compatible systems is responsible for various DOS API calls. Setting the 8 bit register AH to 2 results in character output to be executed. The character to output resides in 8 bit register DL.

So in your first example the ASCII character 02 is printed, but that is a control character so the output shouldn't be b as you state it is but something invisible (02 is start of text). The second example takes the 2, then adds 48 which gives 50 (decimal). That's the ASCII code for the character 2.

My god, I really feel old now... I've done that stuff 20 years ago.


It's pretty straightforward. It's adding 48 (in decimal) to the 8-bit register DL.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜