TASM打印字符串 [英] TASM Print characters of string
本文介绍了TASM打印字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试逐个字符地打印一个字符串,并对其进行遍历.这就是我所拥有的:
I'm trying to print a string character by character, iterating through it. This is what I've got:
.MODEL SMALL
.STACK 64
.DATA
string DB 'Something',0
len equ $-string
.CODE
xor bx, bx
mov si, offset string
Char:
mov al, byte[si + bx]
inc bx
cmp bx, len
je Fin
mov ah, 2
mov dl, al
int 21h
jmp Char
Fin:
mov ax, 4c00h
int 21h
END
我不知道我是否得到正确的字符串mem引用,因为它只显示奇怪的符号.我尝试将30加到dl,以为那是因为ascii表示.
I don't know if I'm getting the right mem reference of string, because it only shows me weird symbols. I tried adding 30 to dl, thinking it was because of the ascii representation.
如何按字符打印字符?
推荐答案
下面是Tasm的一个有效示例,它不会破坏字符串的开头.
Here is a working example with Tasm, that is not mangling the begining of the string.
由于以后移动增量并将je
替换为jnz
It has one less jump due to the moving of the increment later and the replacement of the je
with a jnz
.MODEL SMALL
.STACK 64
.DATA
string DB 'Something'
len equ $-string
.CODE
Entry:
mov ax, @data ;make DS point to our DATA segment
mov ds, ax
xor bx, bx ;bx <-- 0
mov si, offset string ;address of string to print
mov ah, 2 ;we will use repeatedly service #2 of int 21h
Char:
mov dl, [si + bx] ;dl is the char to print
int 21h ;ask DOS to output a single char
inc bx ;point to next char
cmp bx, len
jnz Char ;loop if string not finished
mov ax, 4c00h
int 21h ;DOS exit program with al = exit code
END Entry
这篇关于TASM打印字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文