Kri*_*oks 24 x86 assembly real-mode
mov al,10
add al,15
Run Code Online (Sandbox Code Playgroud)
如何打印' al ' 的值?
mrk*_*rkj 26
你试过int 21h服务2吗? DL是要打印的角色.
mov dl,'A' ; print 'A'
mov ah,2
int 21h
Run Code Online (Sandbox Code Playgroud)
要打印整数值,您必须编写一个循环来将整数分解为单个字符.如果你可以用十六进制打印值,这非常简单.
如果你不能依靠DOS服务,您可能还可以使用BIOSint 10h与AL设置为0Eh或0Ah.
小智 7
汇编语言没有直接打印任何东西的方法.您的汇编程序可能会也可能不会提供提供此类工具的库,否则您必须自己编写它,这将是一个非常复杂的功能.您还必须决定在哪里打印东西 - 在窗口中,在打印机上?在汇编程序中,这些都不是为您完成的.
小智 5
DOS 打印存储在 EAX 中的 32 位值并以十六进制输出(对于 80386+)
(在 64 位操作系统上使用 DOSBOX)
.code
mov ax,@DATA ; get the address of the data segment
mov ds,ax ; store the address in the data segment register
;-----------------------
mov eax,0FFFFFFFFh ; 32 bit value (0 - FFFFFFFF) for example
;-----------------------
; convert the value in EAX to hexadecimal ASCIIs
;-----------------------
mov di,OFFSET ASCII ; get the offset address
mov cl,8 ; number of ASCII
P1: rol eax,4 ; 1 Nibble (start with highest byte)
mov bl,al
and bl,0Fh ; only low-Nibble
add bl,30h ; convert to ASCII
cmp bl,39h ; above 9?
jna short P2
add bl,7 ; "A" to "F"
P2: mov [di],bl ; store ASCII in buffer
inc di ; increase target address
dec cl ; decrease loop counter
jnz P1 ; jump if cl is not equal 0 (zeroflag is not set)
;-----------------------
; Print string
;-----------------------
mov dx,OFFSET ASCII ; DOS 1+ WRITE STRING TO STANDARD OUTPUT
mov ah,9 ; DS:DX->'$'-terminated string
int 21h ; maybe redirected under DOS 2+ for output to file
; (using pipe character">") or output to printer
; terminate program...
.data
ASCII DB "00000000",0Dh,0Ah,"$" ; buffer for ASCII string
Run Code Online (Sandbox Code Playgroud)
不使用软件中断而直接输出到视频缓冲区的替代字符串:
;-----------------------
; Print string
;-----------------------
mov ax,0B800h ; segment address of textmode video buffer
mov es,ax ; store address in extra segment register
mov si,OFFSET ASCII ; get the offset address of the string
; using a fixed target address for example (screen page 0)
; Position`on screen = (Line_number*80*2) + (Row_number*2)
mov di,(10*80*2)+(10*2)
mov cl,8 ; number of ASCII
cld ; clear direction flag
P3: lodsb ; get the ASCII from the address in DS:SI + increase si
stosb ; write ASCII directly to the screen using ES:DI + increase di
inc di ; step over attribut byte
dec cl ; decrease counter
jnz P3 ; repeat (print only 8 ASCII, not used bytes are: 0Dh,0Ah,"$")
; Hint: this directly output to the screen do not touch or move the cursor
; but feel free to modify..
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
125198 次 |
| 最近记录: |