汇编笔记(2) 多个段

;计算a段中各个内存值加上b段各个内存值后存放到c段中
assume cs:code a segment db 1,2,3,4,5,6,7,8 a ends b segment db 1,2,3,4,5,6,7,9 b ends c1 segment db 0,0,0,0,0,0,0,0 c1 ends code segment s: mov ax,a mov ds,ax ;use ds point to a seg mov ax,c1 mov es,ax ;use es point to c seg mov cx,4 mov bx,0 p1: mov ax,[bx] mov es:[bx],ax add bx,2 loop p1 mov ax,b mov ds,ax ;use ds to point b seg mov cx,4 mov bx,0 p2:mov ax,[bx] add es:[bx],ax add bx,2 loop p2 mov ax,4c00h int 21h code ends end s

(1)ds:[bx]所指向的物理地址即可读也可写;

(2)可以通过定义的段的标号作为该段的引用地址

 

可以手动指定数据段和栈段的位置:

assume cs:codeseg,ss:b,ds:a ;注意:这里虽然这么写,但是CPU不会直接把b当成栈,把a当成数据段,还是需要手动指定
a segment
    dw 1,2,3,4,5,6,7,8,9,0ah,0ch,0dh,0eh,0fh,0ffh
a ends

b segment
    dw 0,0,0,0,0,0,0,0
b ends

codeseg segment
start:
    mov ax,a
    mov ds,ax ;use ds to point to a seg
    
    mov ax,b
    mov ss,ax ;use ss to point to b seg,make b seg as a stack
    mov sp,16
    mov bx,0
    
    mov cx,8
s:
    push [bx]
    add bx,2
    loop s
    
    mov ax,4c00h
    int 21h
    
codeseg ends

end start

 

posted @ 2018-04-24 00:19  at0x7c00  阅读(284)  评论(0编辑  收藏  举报
CSDN - ITeye - GitHub  |  HuQiao's Blog  |  业余经营:IT快报