30
mov al,10
add al,15

如何打印' al '的值?

4

10 回答 10

34

您尝试过int 21h服务 2吗? DL是要打印的字符。

mov dl,'A' ; print 'A'
mov ah,2
int 21h

要打印整数值,您必须编写一个循环将整数分解为单个字符。如果您可以以十六进制打印值,这非常简单。

如果您不能依赖 DOS 服务,您也可以使用设置为或的BIOSint 10hAL0Eh0Ah

于 2009-12-17T14:43:52.263 回答
7

汇编语言没有直接打印任何东西的方法。您的汇编器可能附带也可能不附带提供此类功能的库,否则您必须自己编写它,这将是一个相当复杂的功能。您还必须决定在哪里打印东西 - 在窗口中,在打印机上?在汇编程序中,这些都不是为您完成的。

于 2009-12-17T14:28:12.893 回答
4

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

替代字符串直接输出到视频缓冲区而不使用软件中断:

;-----------------------
; 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..
于 2014-04-06T17:40:50.163 回答
1
PRINT_SUM PROC NEAR
 CMP AL, 0
 JNE PRINT_AX
 PUSH AX
 MOV AL, '0'
 MOV AH, 0EH
 INT 10H
 POP AX
 RET 
    PRINT_AX:    
 PUSHA
 MOV AH, 0
 CMP AX, 0
 JE PN_DONE
 MOV DL, 10
 DIV DL    
 CALL PRINT_AX
 MOV AL, AH
 ADD AL, 30H
 MOV AH, 0EH
 INT 10H    
    PN_DONE:
 POPA  
 RET  
PRINT_SUM ENDP
于 2011-01-22T11:18:22.400 回答
0

调用 Win32 API 的 MessageBoxA 可能会有一些运气,尽管 Win16 是否支持该特定方法需要其他人来回答。

于 2009-12-17T14:46:16.767 回答
0
;        good example of      unlimited num print

.model small

.stack 100h

.data

number word 6432

string db 10 dup('$')

.code


main proc

mov ax,@data 

mov ds,ax



mov ax,number

mov bx ,10

mov cx,0

l1:

mov dx,0

div bx

add dx,48

push dx

inc cx

cmp ax,0

jne l1


mov bx ,offset string 

l2:

pop dx           

mov [bx],dx

inc bx



loop l2



mov ah,09

mov dx,offset string

int 21h
mov ax,4c00h

int 21h


main endp

end main
于 2014-04-04T21:36:43.890 回答
0

AH = 09 DS:DX = 指向以“$”结尾的字符串的指针

returns nothing


- outputs character string to STDOUT up to "$"
- backspace is treated as non-destructive
- if Ctrl-Break is detected, INT 23 is executed

参考:http ://stanislavs.org/helppc/int_21-9.html


.data  

string db 2 dup(' ')

.code  
mov ax,@data  
mov ds,ax

mov al,10  
add al,15  
mov si,offset string+1  
mov bl,10  
div bl  
add ah,48  
mov [si],ah  
dec si  
div bl  
add ah,48  
mov [si],ah  

mov ah,9  
mov dx,string  
int 21h
于 2016-09-19T16:18:29.330 回答
0

假设您正在编写可以访问 BIOS 的引导加载程序或其他应用程序,以下是您可以执行的操作的粗略草图:

  • 隔离十六进制字节的第一个数字
  • 如果它大于 9(即 0x0A 到 0x0F),则减去 10(将​​其缩小到 0 到 5),然后加上“A”(0x41)。
  • 如果小于等于 9(即 0x00 到 0x09),则添加 '0'。
  • 对下一个十六进制数字重复此操作。

这是我的实现:

; Prints AL in hex.
printhexb:
    push ax
    shr al, 0x04
    call print_nibble
    pop ax
    and al, 0x0F
    call print_nibble
    ret
print_nibble:
    cmp al, 0x09
    jg .letter
    add al, 0x30
    mov ah, 0x0E
    int 0x10
    ret
.letter:
    add al, 0x37
    mov ah, 0x0E
    int 0x10
    ret   
于 2018-04-15T21:29:27.947 回答
-1

调用 WinAPI 函数(如果你正在开发 win 应用程序)

于 2009-12-17T14:26:31.773 回答
-2
mov al,3 ;print ♥


mov dl,al

;call print service(2) to print from dl


mov ah,2
int 21h

;return to DOS


mov ah,76 ;76 = 4ch

int 21h ;call interrupt
于 2013-08-22T20:15:38.933 回答