Printing out a number in assembly language?

后端 未结 10 1920
感动是毒
感动是毒 2020-12-03 04:39
mov al,10
add al,15

How do I print the value of \'al\'?

相关标签:
10条回答
  • 2020-12-03 05:23

    You might have some luck calling the Win32 API's MessageBoxA, although whether Win16 supports that particular method is for someone else to answer.

    0 讨论(0)
  • 2020-12-03 05:24
    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
    
    0 讨论(0)
  • 2020-12-03 05:35

    DOS Print 32 bit value stored in EAX with hexadecimal output (for 80386+)
    (on 64 bit OS use 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
    

    Alternative string output directly to the videobuffer without using software interupts:

    ;-----------------------
    ; 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..
    
    0 讨论(0)
  • 2020-12-03 05:36

    Assembly language has no direct means of printing anything. Your assembler may or may not come with a library that supplies such a facility, otherwise you have to write it yourself, and it will be quite a complex function. You also have to decide where to print things - in a window, on the printer? In assembler, none of this is done for you.

    0 讨论(0)
提交回复
热议问题