首页 > 解决方案 > 如何调用一个程序并打印它?

问题描述

您好,在一切之前,我是组装新手并试图理解它。我有一个 tasm 程序,我正在尝试进行系统调用并打印此程序的输出,但我找不到如何进行系统调用。

    .MODEL small   
        .DATA
        ;The string to be printed  
        STRING DB '047119047', '$'



        .CODE

;   Purpose:
;       Calculates the check digit for a ten digit ISBN, converts that
;       digit to its ASCII representation and returns that answer.
;
;   Entry:
;
;      isbn = a nine digit ASCII string containing the ISBN
;             (with or without the check digit which is not used here)
;
;   Register usage within the routine:
;
;        AL = current ISBN digit
;        AH = sum of digits so far
;        BX = start pointer into ISBN for each outer loop
;        CX = digit counter (inner loop)
;        DX = start value for digit counter
;        SI = points to current ISBN digit
;
;   Exit:
;
;        AX = ASCII representation of calculated check digit
;
;   Trashed:
;       none
;
;***************************************************************************/


isbncheck proc C isbn:ptr byte
        push    bx
        push    cx
        push    dx
        push    si
        mov     bx,[isbn]               ;
        mov     dx,9                    ; number of digits in raw ISBN
        xor     ax,ax                   ; clear out our total
        cld                             ; count up
@@bigloop:                              ;
        mov     si,bx                   ; point to a digit in the ISBN
        mov     cx,dx                   ; get digit count in CX
@@AddEmUp:                              ;
        lodsb                           ; fetch digit into AL
        and     al,0fh                  ; convert from ASCII
        add     ah,al                   ; add it to our total in AH
        loop    @@AddEmUp               ; do all digits
        inc     bx                      ; and advance the digit pointer
        dec     dx                      ; now decrement digit count
        jnz     @@bigloop               ;   keep going if digits left
        mov     al,ah                   ; move sum into al
        xor     ah,ah                   ; clear out high half
        mov     cl,11                   ; we'll be doing a mod 11 operation
        div     cl                      ; ah = sum mod 11
        mov     al,ah                   ; move calculated check digit to AL
        xor     ah,ah                   ; clear out high half
        or      al,30h                  ; convert to ASCII digit
        cmp     al,3Ah                  ;
        jnz     NotTen                  ;
        mov     al,'X'                  ;
NotTen:                                 ;
        pop     si
        pop     dx
        pop     cx
        pop     bx
        ret                             ; return
isbncheck endp

        END

我希望你们能帮助我。如果我的问题不清楚,请告诉我。所以我可以更清楚地解释它。

标签: assemblyx86

解决方案


我正在尝试进行系统调用并打印此过程的输出

;The string to be printed  
STRING DB '047119047', '$'

由于我可以看到字符串以 '$' 结尾,因此我将向您展示如何在 DOS 环境中执行此操作:

mov dx, offset STRING
mov ah, 09h             ; DOS.PrintString
int 21h

这将从光标所在的屏幕开始输出这 9 个数字(不包括仅用作终止符的“$”字符)。此后光标将超出最后一个字符。

或者,您可以使用循环。这将允许您不必使用那个 '$' 终止符(函数 09h 强制):

    mov si, offset STRING
    mov dl, [si]
More:
    mov ah, 02h       ; DOS.PrintChar
    int 21h
    inc si
    mov dl, [si]
    cmp dl, '$'
    jne More

推荐阅读