uP:Lab7

Z Wiki Rafał (ert16) Trójniak

lab_7a.s

#----------------------------------------------------------------
# Program LAB_7A.S - Asemblery Laboratorium IS II rok
#----------------------------------------------------------------
 
.equ	KERNEL,	0x80	# Linux system functions entry
.equ	WRITE,	0x04	# write data to file function
.equ	EXIT,	0x01	# exit program function
 
.equ	STDOUT,	1
 
.equ	LAST_X,	80
 
	.data
 
line:			# line of characters used in graph
	.space		80, '='
x:			# x coordinate
	.long		0
y:			# y coordinate
	.long		0
periods:		# number of periods (częstotliwość)
	.long		2
x_scale:		# x axis scale coefficient (1/ilość jednostek na linijkę)
	.long		LAST_X - 5
y_shift:		# shift of plotted function (faza)
	.long		25
y_scale:		# y axis scale coefficient (amplituda)
	.long		10
startmsg:		# starting message
	.ascii	"Plot of y=sin(x) function\n"
startlen:		# length of message
	.long		( . - startmsg )
finalmsg:		# final message
	.ascii  "End of plot\n"
finallen:		# length of message
	.long		( . - finalmsg )
newline:		# newline character
	.byte	'\n'
 
	.text
	.global _start
 
_start:
 
#Wypisujemy któtki tekst
	MOVL	$WRITE,%eax	# write function
	MOVL	$STDOUT,%ebx	# file handle in EBX
	MOVL	$startmsg,%ecx	# ECX points to starting message
	MOVL	startlen,%edx	# length of message
	INT	$KERNEL
 
	FINIT			# math coprocessor initialization
	MOVL	$0,x		# starting value of x
next:
	FLDPI			# PI -> ST(0)
	FLDPI			# PI -> ST(0)
#Stos : PI | PI
	FADDP			# PI+PI -> ST(0) / ST(1)+ST(0)->ST(1) and remove ST(0) /
#Stos : 2PI
	FIMUL	periods		# 2PI * number of periods -> ST(0)
#Stos : 2PI* periods
	FIMUL	x		# 2 * PI * x -> ST(0)
#Stos : 2PI* periods *x
	FIDIV	x_scale		# 2 * PI * x / x_scale -> ST(0)
#Stos : (2PI* periods *x)/x_scale
	FSIN			# FSIN( ST(0) ) -> ST(0)
#Stos : sin ( (2PI* periods *x)/x_scale )
	FIMUL	y_scale		# sin() * y_scale -> ST(0)
#Stos : sin ( (2PI* periods *x)/x_scale ) * y_scale
	FIADD	y_shift		# sin() * y_scale + y_shift -> ST(0)
#Stos : sin ( (2PI* periods *x)/x_scale ) * y_scale + y_shift
 
#Składujemy nasz wynik w y, zdejmując jednocześnie go ze stosu
	FISTP	y		# INT( ST(0) ) -> y and remove ST(0)
	NOP
# Ustalamy przy pomocy rejestru EDX ilość wypisywanych znaków
	MOVL	y,%edx		# bytes to be written (y value of graph)
# Wypisuujemy słupek
	MOVL	$WRITE,%eax	# write function
	MOVL	$STDOUT,%ebx	# file handle in EBX
	MOVL	$line,%ecx	# ECX points to line of characters
	INT	$KERNEL
# Wypisujemy znak końca linii
	MOVL	$WRITE,%eax	# write function
	MOVL	$STDOUT,%ebx	# file handle in EBX
	MOVL	$newline,%ecx	# ECX points to '\n' character
	MOVL	$1,%edx		# bytes to be written (1)
	INT 	$KERNEL
# Zwiększamy x, oraz zawijamy pętlę
	INCL	x		# next x value
	CMPL	$LAST_X,x	# last x point ?
	JNZ	next		# no - jump and compute next point
 
#Komentarz końcowy
	MOVL	$WRITE,%eax	# write function
	MOVL	$STDOUT,%ebx	# file handle in EBX
	MOVL	$finalmsg,%ecx	# ECX points to final message
	MOVL	finallen,%edx	# length of message
	INT	$KERNEL
#Kończymy program
	MOVL	$EXIT,%eax	# exit program function
	MOVL	$0,%ebx		# exit code
	INT	$KERNEL
Osobiste