mirror of
https://github.com/KevinMidboe/linguist.git
synced 2026-01-27 19:55:45 +00:00
Add Pep8 Assembly language (#2070)
Pep/8 is a toy assembly language used in some universities for teaching the basics of assembly and low-level programming. Signed-off-by: Lucas Bajolet <lucas.bajolet@gmail.com>
This commit is contained in:
committed by
Colin Seymour
parent
acbab53198
commit
ded651159d
61
samples/Pep8/stri_buf.pep
Normal file
61
samples/Pep8/stri_buf.pep
Normal file
@@ -0,0 +1,61 @@
|
||||
main:
|
||||
|
||||
; Reads a string in stdin, returns the buffer it was read in
|
||||
; Stops reading at the first encounter of a \n character.
|
||||
;
|
||||
; Parameters:
|
||||
; void
|
||||
;
|
||||
; Returns:
|
||||
; - X: Address of the buffer
|
||||
stri: SUBSP 2, i
|
||||
LDA 32, i
|
||||
CALL new
|
||||
CPX buflen, s
|
||||
BRGE strinlrg
|
||||
strinlrg: LDA buflen, d
|
||||
LDX 2, i
|
||||
CALL mult
|
||||
STA buflen
|
||||
CALL new
|
||||
|
||||
buflen: .EQUATE 0
|
||||
|
||||
; Copies the content of a buffer to another one
|
||||
;
|
||||
; Parameters:
|
||||
; - SP + 2: Destination buffer
|
||||
; - SP + 4: Source buffer
|
||||
; - SP + 6: Length to copy
|
||||
memcpy: LDX 0, i
|
||||
memcplp: CPX cpylen, s
|
||||
BREQ memcpout
|
||||
LDBYTEA srcbuf, sxf
|
||||
STBYTEA dstbuf, sxf
|
||||
ADDX 1, i
|
||||
BR memcplp
|
||||
memcpout: RET0
|
||||
; Destination buffer
|
||||
dtsbuf: .EQUATE 2
|
||||
; Source buffer
|
||||
srcbuf: .EQUATE 4
|
||||
; Copy length
|
||||
cpylen: .EQUATE 6
|
||||
|
||||
; Allocates a new structure in the heap
|
||||
;
|
||||
; Parameters:
|
||||
; - A: Length of the structure to allocate (bytes)
|
||||
;
|
||||
; Returns:
|
||||
; - X: Address of the allocated structure
|
||||
new: ADDA hpptr, d
|
||||
LDX hpptr, d
|
||||
STA hpptr, d
|
||||
RET0
|
||||
|
||||
; Pointer to the next available byte on the heap
|
||||
hpptr: .ADDRSS heap
|
||||
; Start of the heap
|
||||
heap: .BLOCK 1
|
||||
.END
|
||||
Reference in New Issue
Block a user