汇编 递归实现打印一个整数

c 语言代码如下

#include <stdio.h>
#include <stdbool.h>
void print(int x){
    
    
    if(x < 10){
    
    
        printf("%d",x);
        return ;
    }
    print(x / 10);
    printf ("%d",x % 10);
}
int main(){
    
    
    print(1234);
}

汇编代码

DATAs SEGMENT
     N DW 6;
     arry DB 35h,78h,25h,13h,8h,0D2H 
     DATA2 DB 20 DUP(0)
DATAs ends	
CODES  SEGMENT
     ASSUME    CS:CODES,DS:DATAS
START:
     mov ax,datas
     mov ds,ax
     
     mov ax,12344
     call print
     MOV  AH,4CH
     INT  21H 
     
     print proc near    
          cmp ax,10 
          jae next:
          mov dl,al 
          add dl,'0'
          mov ah,2
          int 21h
          ret
          next:  
          mov bx ,10  
          mov dx,0
          div bx  
          push dx
          call print  
          pop dx
          mov ah,2 
          add dl,'0'
          int 21h  
          ret   
     print endp
CODES  ENDS
    END   START



猜你喜欢

转载自blog.csdn.net/hddddh/article/details/111602086