You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
144 lines
3.1 KiB
144 lines
3.1 KiB
void strcpy (destination, destination_segment, source, source_segment );
|
|
int strlen (source, source_segment);
|
|
void memcpy (destination, destination_segment, source, source_segment, num_bytes );
|
|
|
|
int strlen (source, source_segment)
|
|
{
|
|
#asm
|
|
#define strlen_SOURCE 4[bp];
|
|
#define strlen_SOURCE_SEGMENT 6[bp];
|
|
push bp
|
|
mov bp,sp
|
|
push ds
|
|
push bx
|
|
|
|
mov ax, strlen_SOURCE_SEGMENT
|
|
mov ds, ax
|
|
|
|
mov bx, strlen_SOURCE
|
|
|
|
label_strlen:
|
|
mov cx, #0x0 ; Set counte to zero
|
|
.label_strlen_loop:
|
|
mov BYTE al, [bx]
|
|
cmp al, #0x0
|
|
je .label_strlen_done
|
|
inc cx ; Count 1
|
|
inc bx ; Look at next char
|
|
jmp .label_strlen_loop
|
|
.label_strlen_done:
|
|
mov ax, cx
|
|
|
|
pop bx
|
|
pop ds
|
|
pop bp
|
|
#endasm
|
|
}
|
|
|
|
void strcpy (destination, destination_segment, source, source_segment )
|
|
char *destination;
|
|
int destination_segment;
|
|
char *source;
|
|
int source_segment;
|
|
{
|
|
#asm
|
|
; copy two strings
|
|
; IN si: the first (zero terminated) string
|
|
; IN di: the second (zero terminated) string
|
|
; OUT SF and ZF (same semantics as cmp)
|
|
|
|
#define DESTINATION 4[bp];
|
|
#define DESTINATION_SEGMENT 6[bp];
|
|
#define SOURCE 8[bp];
|
|
#define SOURCE_SEGMENT 10[bp];
|
|
|
|
push bp
|
|
mov bp,sp
|
|
label_strcpy:
|
|
push ax
|
|
push bx
|
|
push di
|
|
push es
|
|
push si
|
|
push ds
|
|
mov ax, DESTINATION;
|
|
mov di, ax
|
|
mov ax, DESTINATION_SEGMENT;
|
|
mov es, ax
|
|
mov ax, SOURCE;
|
|
mov si, ax
|
|
mov ax, SOURCE_SEGMENT;
|
|
mov ds, ax
|
|
mov cx, 0x050 // TODO(Jørn) Hardcded number of bytes to copy
|
|
.label_strcpy_loop:
|
|
movsb
|
|
cmp cx, 0x0
|
|
je .label_strcpy_end
|
|
dec cx
|
|
jmp .label_strcpy_loop
|
|
.label_strcpy_end:
|
|
pop ds
|
|
pop si
|
|
pop es
|
|
pop di
|
|
pop bx
|
|
pop ax
|
|
pop bp
|
|
|
|
#endasm
|
|
}
|
|
|
|
void memcpy (destination, destination_segment, source, source_segment, num_bytes)
|
|
void *destination;
|
|
int destination_segment;
|
|
void *source;
|
|
int source_segment;
|
|
int num_bytes;
|
|
{
|
|
#asm
|
|
; copy two strings
|
|
; IN si: the first (zero terminated) string
|
|
; IN di: the second (zero terminated) string
|
|
; OUT SF and ZF (same semantics as cmp)
|
|
|
|
#define DESTINATION 4[bp];
|
|
#define DESTINATION_SEGMENT 6[bp];
|
|
#define SOURCE 8[bp];
|
|
#define SOURCE_SEGMENT 10[bp];
|
|
#define NUM_BYTES 12[bp];
|
|
|
|
push bp
|
|
mov bp,sp
|
|
label_memcpy:
|
|
push ax
|
|
push bx
|
|
push di
|
|
push es
|
|
push si
|
|
push ds
|
|
mov ax, DESTINATION;
|
|
mov di, ax
|
|
mov ax, DESTINATION_SEGMENT;
|
|
mov es, ax
|
|
mov ax, SOURCE;
|
|
mov si, ax
|
|
mov ax, SOURCE_SEGMENT;
|
|
mov ds, ax
|
|
mov cx, NUM_BYTES
|
|
.label_memcpy_loop:
|
|
movsb
|
|
cmp cx, 0x0
|
|
je .label_memcpy_end
|
|
dec cx
|
|
jmp .label_memcpy_loop
|
|
.label_memcpy_end:
|
|
pop ds
|
|
pop si
|
|
pop es
|
|
pop di
|
|
pop bx
|
|
pop ax
|
|
pop bp
|
|
|
|
#endasm
|
|
}
|