汇编语言 输出“hello world!”(普通写法&简洁写法)

打印 hello world!

普通写法

assume cs:codesg, ss:stacksg, ds:datasg
datasg segment
      str db 'hello world!$'
datasg ends
stacksg segment
      db 32 dup (0)
stacksg ends
codesg segment
start:
      mov ax, datasg
      mov ds, ax
      mov ax, stacksg
      mov ss, ax
      mov sp, 20h
      lea bx, str
output:
      mov dl, [bx]
      cmp dl, '$'
      je stop
      mov ah, 02H
      int 21h
      inc bx
      jmp output
 stop:
      mov ax, 4c00h
      int 21h
codesg ends
end start

简洁写法

.8086
.MODEL small
.data
    str db 'hello world!$'
.stack 20H
.code
start:
      mov ax, @data
      mov ds, ax
      lea bx, str 
output:
      mov dl, [bx]
      cmp dl, '$'
      je stop
      mov ah, 02H
      int 21h
      inc bx
      jmp output
 stop:
      mov ax, 4c00h
      int 21h
end start

猜你喜欢

转载自blog.csdn.net/weixin_44169557/article/details/106808765