]Simple assembly of "hello world" string output

Publisher:huanxinLatest update time:2015-10-27 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
The hello world program is a must-have for beginners of every language. Here is a brief source code in assembly form:

And rough notes. You can check the function of interrupt 21 on the Internet. I hope it can help you.

 

 

 

 

; Function: hello world! Output of the string

;Register association: code segment code is associated with code segment register CS,
;data segment data is associated with data segment register DS.
assume CS:code,DS:data  ;Note: assume is a pseudo instruction and is not translated during scan compilation

 

;data segment definition
data segment
 string db 'Hello world!','$'  ;Avoid string terminator $
data ends

 

; Code segment definition
code segment

;Program starts
:
 mov ax,data   ;Load the data segment address into the AX register
 mov ds,ax  ;Load the data segment address into DS through the general register AX
 mov dx,offset string  ;Load the string segment address into DX
 mov ah,09h  ;Call DOS function 09H, pass in parameter DS:DX=string address, end the string with '$'

 int 21h
 mov ah,4ch  ;Call DOS function 4CH, end with return code, return code exists in AL
 int 21h
code ends   ;Code segment definition ends
end start   ;Program ends

 

Disassembly analysis of hello world:

The disassembly results are as follows:

-u
0C32:0000 B8310C        MOV     AX,0C31
0C32:0003 8ED8          MOV     DS,AX
0C32:0005 BA0000        MOV     DX,0000
0C32:0008 B409          MOV     AH,09
0C32:000A CD21          INT     21
0C32:000C B44 C          MOV     AH,4C
0C32: 000E CD21          INT     21
0C32:0010 0426          ADD     AL,26
0C32:0012 807F0403      CMP     BYTE PTR [BX+04],03
0C32:0016 7507          JNZ     001F
0C32:0018 26            ES:
0C32:0019 807F0A00      CMP     BYTE PTR [BX+0A],00
0C32:001D 7437          JZ      0056
0C32:001F A15827        MOV     AX,[2758]

The single step is as follows:

-t

AX=0C31  BX=0000  CX=0020  DX=0000  SP=0000  BP=0000  SI=0000  DI=0000
DS=0C21  ES=0C21  SS=0C31  CS=0C32  IP=0003   NV UP EI PL NZ NA PO NC
0C32:0003 8ED8          MOV     DS,AX

From the disassembled code, we can know that the segment address of the data segment is assigned by the OS to 0C31 and sent to AX

The code end segment address is 0C32 and is latched by CS.

The stack segment address is the same as the data segment address, but SP and IP have the same starting value, so it may cause some problems.

 

Continue single-stepping:

-t

AX=0C31  BX=0000  CX=0020  DX=0000  SP=0000  BP=0000  SI=0000  DI=0000
DS=0C31  ES=0C21  SS=0C31  CS=0C32  IP=0005   NV UP EI PL NZ NA PO NC
0C32:0005 BA0000        MOV     DX,0000

The value of AX has been sent to DS. It can be seen that the starting value of the address in the general segment is 0.

 

Single step:

0C32:0005 BA0000        MOV     DX,0000
-t

AX=0C31  BX=0000  CX=0020  DX=0000  SP=0000  BP=0000  SI=0000  DI=0000
DS=0C31  ES=0C21  SS=0C31  CS=0C32  IP=0008   NV UP EI PL NZ NA PO NC
0C32:0008 B409          MOV     AH,09

The value of DX is reset to 0.

 

Single step:

AX=0931  BX=0000  CX=0020  DX=0000  SP=0000  BP=0000  SI=0000  DI=0000
DS=0C31  ES=0C21  SS=0C31  CS=0C32  IP=000A   NV UP EI PL NZ NA PO NC
0C32:000A CD21          INT     21

09 is sent to the high eight bits of AX

 

Single step:

AX=0931  BX=0000  CX=0020  DX=0000  SP=FFFA  BP=0000  SI=0000  DI=0000
DS=0C31  ES=0C21  SS=0C31  CS=00A7  IP=107C   NV UP DI PL NZ NA PO NC
00A7:107C 90NOP           

Trigger interrupt 21, program jump

The following are some interrupt functions. Since the students have not learned them yet, the disassembly analysis will stop here for the time being.

Finally, take a look at the memory storage:

-d 0c31:0
0C31:0000  48 65 6C 6C 6F 20 77 6F-72 6C 64 21 24 00 00 00   Hello world!$...
0C31:0010  B8 31 0C 8E D8 BA 00 00-B4 09 CD 21 B4 4C CD 21   .1.........!.L.!
0C31:0020  04 26 80 7F 04 03 75 07-26 80 7F 0A 00 74 37 A1   .&....u.&... .t7.
0C31:0030  58 27 39 06 36 22 72 14-BE 36 22 8B  1C  FF 04   2B ..6". 0C31:0050  1C FF 04 D1 E3 D1 E3 8B-36 92 12 8B 46 08 8B 56  ........6...F..V 0C31:0060  0A 89 00 89 50 02 5E 5D-C3 90 55 8B EC 83 EC 18  ....P.^]..U..... 0C31:0070  57 56 8B 5E 04 8B 07 8B-57 02 89 46 F8 89 56 FA  WV.^....W..F..V.
 
 
 
 

It can be seen that our procedure was successful.


Reference address:]Simple assembly of "hello world" string output

Previous article:Calculation of delay time in single chip microcomputer C language
Next article:MSP430 clock setting and application summary

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号