Compile learning notes for beginners (5)-programs with multiple segments

Source: Internet
Author: User

Getting started with crazy summer vacation Study Notes (5)-a program containing multiple segments


Reference: Chapter 6th of Assembly Language


1. Use Data in the code.

assume cs:codecode segmentdw 0123h,0456h,0789h,0defhmov ax,0mov bx,0mov ax,4c00Hint 21hcode endsend


DW indicates defining the font data and DB indicates defining the byte data.


The above code is compiled and connected, and debug is used.-U Cs: 0 is used to view the assembly code, and mov ax, 0 mov BX, and 0 are not found. The direct operation is not normal. Because the computer does not know the data and the code. If-u Cs: 8, you can see mov ax, 0 mov BX, 0, and so on.

Add the program entry to the correct method.


assume cs:codecode segmentdw 0123h,0456h,0789h,0defhstart:mov ax,0mov bx,0mov ax,4c00Hint 21hcode endsend start

You can change start to another name, as long as the entrance is the same as the end name.


2. Use stacks in code


Example: swap 0123 H and 0456 H

DW 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 applied for stack space

SP 30 h set the starting position of the stack top

assume cs:codecode segmentdw 0123h,0456h,0789h,0abch,0defh,0fedh,0cbah,0987hdw 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0start:mov ax,csmov ss,axmov sp,30hpush cs:[0]push cs:[2]pop cs:[0]pop cs:[2]mov ax,4c00hint 21hcode endsend start


3. Put data, code, and stack into different segments


Example: store data in data segments in reverse mode

assume cs:code,ds:data,ss:stackdata segmentdw 0123h,0456h,0789h,0abch,0defh,0fedh,0cbah,0987hdata endsstack segmentdw 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0stack endscode segmentstart:mov ax,datamov ds,axmov ax,stackmov ss,axmov sp,20hmov bx,0mov cx,8s:push  [bx]add bx,2loop smov bx,0mov cx,8s0:pop  [bx]add bx,2loop s0mov ax,4c00hint 21hcode endsend start

Three segments, data segments, stack segments, and code segments are defined here. DS and SS values must be specified in the Code segment.




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.