mov al,10
add al,15
Wie drucke ich den Wert von ' al '?
Haben Sie int 21h
Service 2 ausprobiert? DL
ist das zu druckende Zeichen.
mov dl,'A' ; print 'A'
mov ah,2
int 21h
Um den Ganzzahlwert zu drucken, müssen Sie eine Schleife schreiben, um die Ganzzahl in einzelne Zeichen zu zerlegen. Wenn Sie den Wert in hexadezimal drucken möchten, ist dies ziemlich trivial.
Wenn Sie sich nicht auf DOS-Dienste verlassen können, können Sie möglicherweise auch das BIOS int 10h
verwenden, wobei AL
auf 0Eh
oder 0Ah
eingestellt ist.
Assembler hat keine direkte Möglichkeit, etwas zu drucken. Ihr Assembler verfügt möglicherweise über eine Bibliothek, die eine solche Einrichtung zur Verfügung stellt. Andernfalls müssen Sie sie selbst schreiben. Dies ist eine recht komplexe Funktion. Sie müssen auch entscheiden, wo Sie drucken sollen - in einem Fenster, auf dem Drucker? Im Assembler wird nichts davon für Sie erledigt.
In EAX gespeicherter 32-Bit-Wert mit hexadezimaler Ausgabe (für 80386+)
(unter 64-Bit-Betriebssystemen DOSBOX verwenden)
.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
Alternative String-Ausgabe direkt in den Videopuffer, ohne Software-Interrupts zu verwenden:
;-----------------------
; 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..
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
AH = 09 DS: DX = Zeiger auf eine Zeichenfolge, die auf "$" endet
returns nothing
- outputs character string to STDOUT up to "$"
- backspace is treated as non-destructive
- if Ctrl-Break is detected, INT 23 is executed
ref: 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
Angenommen, Sie schreiben einen Bootloader oder eine andere Anwendung, die Zugriff auf das BIOS hat, hier eine grobe Skizze dessen, was Sie tun können:
Hier ist meine Umsetzung davon:
; 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
Sie haben vielleicht etwas Glück, die MessageBoxA der Win32-API aufzurufen, ob Win16 diese bestimmte Methode unterstützt, ist jedoch die Antwort einer anderen Person.