🤯🤯🤯🤯🤯🤯🤯🤯🤯
This commit is contained in:
@ -1,61 +0,0 @@
|
||||
# Makefile to make executables from alpha source code files
|
||||
# and also make executables from some sample assembly files execising the alpha library
|
||||
#
|
||||
# Carl Alphonce
|
||||
# April 20, 2024
|
||||
|
||||
# The alpha compiler and flags (adjust the flags as needed)
|
||||
AC := ./alpha
|
||||
AFLAGS := -tok -asc -tc -st -ir -cg
|
||||
|
||||
# The preprocessor and flags (you should not adjust these)
|
||||
CPP := cpp
|
||||
CPPFLAGS := -P -x c
|
||||
|
||||
# Adjust for the library your team is using (register-based or stack-based parameter passing)
|
||||
|
||||
ALPHA_LIB = alpha_lib_reg.s ## Register-based parameter passing
|
||||
#ALPHA_LIB = alpha_lib_st.s ## Stack-based parameter passing
|
||||
|
||||
# Adjust for the parameter passing approach your compiler uses:
|
||||
# alpha_driver_reg.s for register-based parameter passing
|
||||
# alpha_driver_st.s for stack-based parameter passing
|
||||
# This file provides a main function that packages up argv[1] (or "") as an alpha string
|
||||
# (type 1->character) and calls entry with that argument
|
||||
|
||||
ALPHA_DRIVER = alpha_driver_reg.s ## Register-based parameter passing
|
||||
#ALPHA_DRIVER = alpha_driver_st.s ## Stack-based parameter passing
|
||||
|
||||
|
||||
# Create an assembly (.s) file from an alpha source file
|
||||
# This involves several steps:
|
||||
%.s : %.alpha
|
||||
@mv $< $<._temporary_ # 1. rename input file so we can us it as
|
||||
@$(CPP) $(CPPFLAGS) $<._temporary_ > $< # 2. input to CPP, writing output to original filename
|
||||
@$(AC) $(AFLAGS) $< # 3. run the alpha compiler on the pre-processed file
|
||||
@mv $<._temporary_ $< # 4. restore the original input file
|
||||
|
||||
|
||||
|
||||
# Examples of assembly code using the alpha library files
|
||||
# In these examples the calling code is in assembly, and defines main (so the driver is not included here)
|
||||
|
||||
# Example #1: calling the printBoolean function
|
||||
printBoolean : printBoolean_reg.s
|
||||
@gcc $< $(ALPHA_LIB) -no-pie -o $@
|
||||
|
||||
# Example #2: calling the printInt function
|
||||
printInt : printInt_reg.s
|
||||
@gcc $< $(ALPHA_LIB) -no-pie -o $@
|
||||
|
||||
# Example #3: calling the reserve and release functions
|
||||
reserve_release : reserve_release_reg.s
|
||||
@gcc $< $(ALPHA_LIB) -no-pie -o $@
|
||||
|
||||
|
||||
# The rule for assembling .s files and linking them together (using the gcc compiler driver)
|
||||
# to produce an executable (assuming no earlier make rule triggers first)
|
||||
|
||||
% : %.s $(ALPHA_LIB) $(ALPHA_DRIVER)
|
||||
@gcc $< $(ALPHA_LIB) $(ALPHA_DRIVER) -no-pie -o $@
|
||||
|
@ -1,26 +0,0 @@
|
||||
.file "printBoolean.c"
|
||||
.text
|
||||
.globl main
|
||||
.type main, @function
|
||||
main:
|
||||
.LFB0:
|
||||
pushq %rbp
|
||||
movq %rsp, %rbp
|
||||
|
||||
movb $1, %dil # the representation of 'true'
|
||||
call printBoolean
|
||||
movb $10, %dil
|
||||
call printCharacter
|
||||
|
||||
movb $0, %dil # the representation of 'false'
|
||||
call printBoolean
|
||||
movb $10, %dil
|
||||
call printCharacter
|
||||
|
||||
movl $0, %eax
|
||||
popq %rbp
|
||||
ret
|
||||
.LFE0:
|
||||
.size main, .-main
|
||||
.ident "GCC: (GNU) 6.4.0"
|
||||
.section .note.GNU-stack,"",@progbits
|
@ -1,22 +0,0 @@
|
||||
.file "printInt.c"
|
||||
.text
|
||||
.globl main
|
||||
.type main, @function
|
||||
main:
|
||||
.LFB0:
|
||||
pushq %rbp
|
||||
movq %rsp, %rbp
|
||||
|
||||
movl $10, %edi # Move the immediate value 10 to %edi
|
||||
call printInteger # call the alpha_lib function printInteger
|
||||
|
||||
movl $10, %edi # Put the \n character (decimal 10) into %edi
|
||||
call printCharacter # then call the alpha_lib function printCharacter
|
||||
|
||||
movl $0, %eax
|
||||
popq %rbp
|
||||
ret
|
||||
.LFE0:
|
||||
.size main, .-main
|
||||
.ident "GCC: (GNU) 6.4.0"
|
||||
.section .note.GNU-stack,"",@progbits
|
@ -1,37 +0,0 @@
|
||||
.file "reserve_release.c"
|
||||
.text
|
||||
.globl main
|
||||
.type main, @function
|
||||
main:
|
||||
.LFB0:
|
||||
pushq %rbp
|
||||
movq %rsp, %rbp
|
||||
subq $16, %rsp
|
||||
|
||||
movl $8, %edi # move sizeof(*a) into %edi
|
||||
call reserve # call alpha_lib_reg function reserve
|
||||
|
||||
movq %rax, -8(%rbp) # put the returned pointer on the stack at offset -8
|
||||
|
||||
movq -8(%rbp), %rax # put base pointer of struct (a) into %rax
|
||||
movl $20, (%rax) # put value 20 into location pointed at by %rax --> (*a).x
|
||||
movq -8(%rbp), %rax # put base pointer of struct (a) into %rax
|
||||
movl $45, 4(%rax) # put value 45 into location 4(%rax) --> (*a).y
|
||||
movq -8(%rbp), %rax # put base pointer of struct (a) into %rax
|
||||
movl 4(%rax), %eax # move (*a).y into %eax
|
||||
movl %eax, %edi # and then into %edi
|
||||
call printInteger # call alpha_lib_reg function printInteger
|
||||
movl $10, %edi # move '\n' into %edi
|
||||
call printCharacter # call alpha_lib_reg function printCharacter
|
||||
|
||||
movq -8(%rbp), %rax # put base pointer of struct (a) into %rax
|
||||
movq %rax, %rdi # and then into %rdi
|
||||
call release # call alpha_lib_reg function reserve
|
||||
|
||||
movl $0, %eax
|
||||
leave
|
||||
ret
|
||||
.LFE0:
|
||||
.size main, .-main
|
||||
.ident "GCC: (GNU) 6.4.0"
|
||||
.section .note.GNU-stack,"",@progbits
|
24
library/std.alpha
Normal file
24
library/std.alpha
Normal file
@ -0,0 +1,24 @@
|
||||
(* Standard Alpha Library - Provided by Carl *)
|
||||
|
||||
type string: 1 -> character
|
||||
type BooleanXBoolean: [Boolean: x; Boolean: y]
|
||||
type characterXcharacter: [character: x; character: y]
|
||||
type integerXinteger: [integer: x; integer: y]
|
||||
|
||||
type Boolean2Boolean: Boolean -> Boolean
|
||||
type integer2integer: integer -> integer
|
||||
type character2integer: character -> integer
|
||||
type Boolean2integer: Boolean -> integer
|
||||
type string2integer: string -> integer
|
||||
type integerXinteger2integer: integerXinteger -> integer
|
||||
type integerXinteger2Boolean: integerXinteger -> Boolean
|
||||
type characterXcharacter2Boolean: characterXcharacter -> Boolean
|
||||
type BooleanXBoolean2Boolean: BooleanXBoolean -> Boolean
|
||||
type integer2address: integer -> address
|
||||
type address2integer: address -> integer
|
||||
|
||||
external function printInteger: integer2integer
|
||||
external function printCharacter: character2integer
|
||||
external function printBoolean: Boolean2integer
|
||||
|
||||
function entry: string2integer
|
Reference in New Issue
Block a user