8086程序打印字符串示例

2021年4月10日12:44:04 发表评论 772 次浏览

问题:编写一个汇编级程序以打印给定的字符串

例子:

Input String: "This is a sample string" 
Output: This is a sample string


Input String: "Geeks for Geeks" 
Output: Geeks for Geeks

说明:

  1. 创建一个字符串
  2. 使用LEA命令在dx中加载字符串的有效地址
  3. 通过在AH中用9H调用中断来打印字符串
  4. 该字符串必须以" $"符号结尾

程序

.MODEL SMALL 
.STACK 100H 
.DATA 
  
;The string to be printed 
STRING DB 'This is a sample string' , '$'
  
.CODE 
MAIN PROC FAR 
  MOV AX, @DATA 
  MOV DS, AX 
  
  ; load address of the string 
  LEA DX, STRING 
  
  ;output the string
  ;loaded in dx 
  MOV AH, 09H
  INT 21H 
  
  ;interrupt to exit
  MOV AH, 4CH
  INT 21H 
  
MAIN ENDP 
END MAIN

输出如下:

This is a sample string

注意:

该程序无法在在线编辑器上运行, 请使用MASM运行该程序, 并使用dos框运行MASM, 你可以使用任何8086仿真器运行该程序。


木子山

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: