What does ADD al, '0' do, and why use it before printing an integer digit?

前端 未结 2 1308
礼貌的吻别
礼貌的吻别 2021-01-25 17:09

I am a novice in assembly language programming
I searched for binary search program and found this and I tried understand the program. It\'s working fine but I couldn\'t un

相关标签:
2条回答
  • 2021-01-25 17:44
    bsearch proc term:DWORD,array:DWORD,asize:DWORD
    
        mov eax,array
        mov ecx,array
        add ecx,asize
        @@:
        cmp eax,ecx
        jg not_found
        mov edx,eax
        add edx,ecx
        shr edx,1
        xchg DWORD PTR [edx],eax
        cmp eax,term
        xchg DWORD PTR [edx],eax
        jg search_right
        jl search_left
        mov eax,edx
        sub eax,array
        ret
        search_right:
        mov ecx,edx
        jmp @B
        search_left:
        mov eax,edx
        jmp @B
        not_found:
        mov eax,-1
        ret
    bsearch endp
    
    0 讨论(0)
  • 2021-01-25 17:50

    add al, '0' converts some 1 digit number to the corresponding ASCII code in order to display it at the screen as a result value on success.

    mov res, al stores the value of the register AL in the first byte of the variable RES. As long as RES points to a string 'POSITION',13,10,'$', the value of AL will be stored on top of the character 'P' of this string and if, for example AL=33h, the string becomes '3OSITION',13,10,'$'.

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