From 35a18609864470b3dc49f3a9a6cb6ec93e57300d Mon Sep 17 00:00:00 2001 From: mrb0nk500 Date: Thu, 25 Feb 2021 12:43:11 -0500 Subject: - Implemented the multiply expression into the assembler. - Implemented support for the SIB addressing mode into the assembler. SIB is short for "Scale Index, and Base", and works much like x86's version of SIB (scale*index+base), although my version supports any scale value between 1, and 256. - Redid the line shifting routine in SuBEditor. It now uses memcpy, and memset to do that, and also supports shifting the line left, or right by any number of characters. --- programs/sub-suite/libc.s | 91 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 67 insertions(+), 24 deletions(-) (limited to 'programs/sub-suite/libc.s') diff --git a/programs/sub-suite/libc.s b/programs/sub-suite/libc.s index 53e936a..b34d2d3 100644 --- a/programs/sub-suite/libc.s +++ b/programs/sub-suite/libc.s @@ -187,7 +187,7 @@ toupper: ; Input: D = size in bytes to allocate. ; Output: A = Pointer to allocated memory. ; Caller preserved registers: D. -; Callie preserved registers: B, X, Y. +; Callee preserved registers: B, X, Y. malloc: phb.q ; Preserve B. @@ -272,7 +272,7 @@ malloc: ; Input: D = Pointer to allocated memory. ; Output: none. ; Caller preserved registers: D. -; Callie preserved registers: A, B, X, Y, E. +; Callee preserved registers: A, B, X, Y, E. free: pha.q ; Preserve A. @@ -405,31 +405,74 @@ free: pla.q ; Restore A. rts ; End of free. - ; memcpy: memory to memory copy. -; Input: A = Destination pointer. B = Source pointer. Y = Number of bytes to copy. +; Input: D = Destination pointer. S = Source pointer. F = Number of bytes to copy. ; Output: A = Destination pointer. -; Caller preserved registers: none. -; Callie preserved registers: none. +; Caller preserved registers: D, S, F. +; Callee preserved registers: B. memcpy: - pha.q ; Preserve the return value. - pha.q ; Push the destination pointer on the stack. - phb.q ; Push the source pointer on the stack. - phy.q ; Push the size on the stack. - and #0 ; Reset A. - tab ; Reset B. - cpy #0 ; Is the size zero? - beq @end ; Yes, so we're done. + phb.q ; Preserve B. + xor b, b ; Reset B. + mov a, d ; Set the return value to the destination pointer. + cmp f, #0 ; Is the size zero? + beq @end ; Yes, so we're done. @loop: - lda (sp+9) ; Get a byte from the source. - sta (sp+17) ; Copy it to the destination. - inc.q sp+9 ; Increment the source pointer. - inc.q sp+17 ; Increment the destination pointer. - dey ; Decrement the size. - beq @end ; The size is zero, so we're done. - bra @loop ; Keep looping. + mov (d+b), (s+b) ; Copy a byte from the source, into the destination. + inb ; Increment the counter. + cmp b, f ; Is the counter the same as the size? + bne @loop ; No, so keep looping. +@end: + plb.q ; Restore B. + rts ; End of memcpy. + + +; memset: Set memory to some value. +; Input: D = Destination pointer. S = Constant value. F = Number of bytes to set. +; Output: A = Destination pointer. +; Caller preserved registers: D, S, F. +; Callee preserved registers: B. + +memset: + phb.q ; Preserve B. + xor b, b ; Reset B. + mov a, d ; Set the return value to the destination pointer. + cmp f, #0 ; Is the size zero? + beq @end ; Yes, so we're done. +@loop: + mov (d+b), s ; Set the destination byte, to the constant value. + inb ; Increment the counter. + cmp b, f ; Is the counter the same as the size? + bne @loop ; No, so keep looping. +@end: + plb.q ; Restore B. + rts ; End of memset. + + +; max: Get the largest of two integers. +; Input: D = First value, S = Second value. +; Output: A = Largest of the two values. +; Caller preserved registers: D, S. +; Callee preserved registers: None. + +max: + mov a, s ; Set the return value to the second value. + cmp d, s ; Is the first value greater than the second value? + beq @end ; No, so we're done. + mcs a, d ; Set the return value to the first value if so. +@end: + rts ; End of max. + + +; min: Get the smallest of two integers. +; Input: D = First value, S = Second value. +; Output: A = Smallest of the two values. +; Caller preserved registers: D, S. +; Callee preserved registers: None. + +min: + mov a, s ; Set the return value to the second value. + cmp d, s ; Is the first value less than the second value? + mcc a, d ; Set the return value to the first value if so. @end: - ads #$18 ; Clean up the stack frame. - pla.q ; Restore the return value. - rts ; End of memcpy. + rts ; End of min. -- cgit v1.2.3-13-gbd6f