11.04.2005, 01:56
общий
это ответ
Здравствуйте, t17fenics!
В приложении приведена процедура HTOA (Standard Library for Assembly Language Programmers by Randall Hyde).
Приложение:
stdlib segment para public ‘slcode‘ assume cs:stdlib extrn sl_malloc:far;;astr db 8 dup (?)aindex dw 0;; HTOA- Converts value in AL to a string of length two containing two; hexadecimal characters. A pointer to this string gets returned; in the ES:DI registers. Returns carry clear if no error. Returns; carry set if there isn‘t enough room on the heap to allocate the; string.; public sl_htoasl_htoa proc far push ax bx cx mov cs:aindex, 0 call hextoa;; Move the digit string out onto the heap and return a pointer to it in; es:si.; mov cx, cs:aindex mov bx, cx ;Save for later. inc cx call sl_malloc ;Allocate storage for string. jc BadHTOACopyStrLp: mov al, cs:astr[bx] mov es:[di][bx], al dec bx jns CopyStrLp clc pop cx bx ax ret;BadHTOA: stc pop cx bx ax retsl_htoa endp;;; WTOA- Converts the binary value in AX to a string of four hexadecimal; characters. Returns a pointer to the string in ES:DI. Returns; carry clear if no error, carry set if an error occurred (not enough; space available in heap).; public sl_wtoasl_wtoa proc far push ax bx cx mov cs:aindex, 0 xchg al, ah call hextoa xchg al, ah call hextoa;; Move the digit string out onto the heap and return a pointer to it in; es:si.; mov cx, cs:aindex mov bx, cx ;Save for later. inc cx call sl_malloc ;Allocate storage for string. jc BadWTOACopyStrLp2: mov al, cs:astr[bx] mov es:[di][bx], al dec bx jns CopyStrLp2 clc pop cx bx ax ret;BadWTOA: stc pop cx bx ax retsl_wtoa endp;;;hextoa proc near push ax mov ah, al shr al, 1 shr al, 1 shr al, 1 shr al, 1 add al, 90h daa adc al, 40h daa call putit mov al, ah and al, 0fh add al, 90h daa adc al, 40h daa call putit pop ax rethextoa endp;; PutIt- Writes the character in AL to the "astr" buffer. Also zero; terminates the string and increments aindex. Note: no need to preserve; DI here because no one else uses it.;PutIt proc near mov di, cs:aindex mov cs:astr[di], al mov byte ptr cs:astr+1[di], 0 inc cs:aindex retPutIt endp;stdlib ends end