Category : Assembly Language Source Code
Archive   : STDLIB_A.ZIP
Filename : STRREV2.ASM

 
Output of file : STRREV2.ASM contained in archive : STDLIB_A.ZIP
stdlib segment para public 'slcode'
assume cs:stdlib
;
extrn sl_malloc:far
;
;
; strrev2- reverses the characters in a string.
;
; inputs:
;
; ES:DI- Points at the string to reverse.
;
; outputs:
;
; ES:DI- Points at new string on the heap.
; Carry=1 if memory allocation error, 0 if no error.
;
;
; Created by Mike Blaszczak (.B ekiM) 8/8/90
; Some minor tweaking by R. Hyde 8/9/90
;
;
public sl_strrev2
;
;
sl_strrev2 proc far
push ds
push si
push ax
push cx
pushf
cld
;
;
; Compute the length (+1 for zero byte) of the string:
;
mov cx, 0ffffh
mov al, 0
repne scasb
neg cx
dec cx
;
; Save ptr to end of the string
;
mov si, es
mov ds, si
lea si, -1[di] ;Points at zero byte.
;
; Allocate storage for the new string:
;
mov ax, cx ;Save length
call sl_malloc
mov cx, ax ;Restore length
jc BadStrRev
push es ;Save ptr to string.
push di
;
; Note that string length is always at least one (for the zero byte).
; Copy and reverse the string down here.
;
CopyBytes: dec si
mov al, [si]
stosb
loop CopyBytes
mov byte ptr es:[di], 0
pop di ;Restore ptr to new string.
pop es
;
popf
pop cx
pop ax
pop si
pop ds
clc
ret
;
BadStrRev: popf
pop cx
pop ax
pop si
pop ds
stc
ret
sl_strrev2 endp
;
;
stdlib ends
end


  3 Responses to “Category : Assembly Language Source Code
Archive   : STDLIB_A.ZIP
Filename : STRREV2.ASM

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/