/Articles/Forth/HTML/CodeAsm/amforth.html
0,0 → 1,211
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title> amforth.asm </title>
<meta name="keywords" content="amforth programming language Forth ATmega ATMEL">
<meta name="description" content="amforth - laguage Forth for ATMEL ATmega">
<!-- AUTOINCLUDE START "Page/Head.en.ihtml" DO NOT REMOVE -->
<link rel="StyleSheet" href="../../../../Web/CSS/MLAB.css" type="text/css" title="MLAB Basic Style">
<link rel="StyleSheet" href="../../../../Web/CSS/MLAB_Print.css" type="text/css" media="print">
<link rel="shortcut icon" type="image/x-icon" href="../../../../Web/PIC/MLAB.ico">
<script type="text/javascript" src="../../../../Web/JS/MLAB_Menu.js"></script>
<!-- AUTOINCLUDE END -->
</head>
 
<body lang="en">
 
<!-- AUTOINCLUDE START "Page/Header.en.ihtml" DO NOT REMOVE -->
<!-- ============== HEADER ============== -->
<div class="Header">
<script type="text/javascript">
<!--
SetRelativePath("../../../../");
DrawHeader();
// -->
</script>
<noscript>
<p><b> JavaScript is required for including of the header </b></p>
</noscript>
</div>
<!-- AUTOINCLUDE END -->
 
<!-- AUTOINCLUDE START "Page/Menu.en.ihtml" DO NOT REMOVE -->
<!-- ============== MENU ============== -->
<div class="Menu">
<script type="text/javascript">
<!--
SetRelativePath("../../../../");
DrawMenu();
// -->
</script>
<noscript>
<p><b> JavaScript is required for including of the menu </b><p>
</noscript>
</div>
<!-- AUTOINCLUDE END -->
 
<!-- ============== TEXT ============== -->
<div class="Text">
 
<h1> amforth.asm </h1>
 
<p>
<input type=button onClick="history.back()" value="Back">
<input type=button onClick="history.forward()" value="Forward">
<a href="../WordList.en.html">Jump to Vocabulary</a>
</p>
 
<pre>
;;;; avr forth
;;;;
;;;; GPL V2 (only)
 
.set pc_ = pc
 
.org $0000
rjmp reset
 
.org pc_
; main entry point
reset:
clr zerol
clr zeroh
; init first user data area
ldi zl, low(heap)
ldi zh, high(heap)
movw upl, zl
; init return stack pointer
ldi temp0,low(ramend)
out SPL,temp0
std Z+2, temp0
ldi temp1,high(ramend)
out SPH,temp1
std Z+3, temp1
 
; init parameter stack pointer
ldi yl,low(stackstart)
std Z+6, yl
ldi yh,high(stackstart)
std Z+7, yh
 
; allocate space for User Area
.set heap = heap + USERSIZE
 
; load Forth IP with starting word
ldi xl, low(PFA_COLD)
ldi xh, high(PFA_COLD)
; the following should be turnkey-action, but adds a few more words to the the dictionary
call_ device_init
; its a far jump...
jmp_ DO_NEXT
 
; ISR routines
.include &quot;words/intx.asm&quot;
.include &quot;words/usart.asm&quot;
 
; lower part of the dictionary
.include &quot;dict_minimum.asm&quot;
.if dict_optional==1
.include &quot;dict_optional.asm&quot;
.endif
 
.set lowflashlast = pc
 
; high part of the dictionary (primitives and words for self programming)
.org nrww
; the inner interpreter.
DO_DODOES:
adiw wl, 1
savetos
movw tosl, wl
 
pop wh
pop wl
 
push xh
push xl
movw xl, wl
rjmp DO_NEXT
 
DO_COLON: ; 31 CPU cycles to ijmp
push xh
push xl ; PUSH IP
adiw wl, 1 ; set W to PFA
movw xl, wl
 
DO_NEXT: ; 24 CPU cycles to ijmp
brts DO_INTERRUPT
movw zl,xl ; READ IP
lsl zl
rol zh
lpm wl, Z+
lpm wh, Z ; done read IP
adiw xl, 1 ; INC IP
 
DO_EXECUTE: ; 12 cpu cycles to ijmp
movw zl, wl
lsl zl
rol zh
lpm temp0, Z+
lpm temp1, Z
movw zl, temp0
ijmp
 
DO_INTERRUPT: ; 12 cpu cycles to rjmp (+12=24 to ijmp)
; here we deal with interrupts the forth way
lds temp0, intcur
ldi zl, LOW(intvec)
ldi zh, HIGH(intvec)
add zl, temp0
adc zh, zeroh
ldd wl, Z+0
ldd wh, Z+1
 
clt ; clear the t flag to indicate that the interrupt is handled
rjmp DO_EXECUTE
 
.include &quot;dict_high.asm&quot;
 
.if dict_optional==2
.include &quot;dict_optional.asm&quot;
.endif
.set flashlast = pc
 
.eseg
.dw lowflashlast ; DP
.dw VE_HEAD ; HEAD
.dw heap ; HEAP
.dw edp ; EDP
.dw XT_VER ; TURNKEY
.dw baud_rate ; BAUDRATE
; 1st free address in EEPROM, see above
edp:
.cseg
</pre>
 
<p>
<input type=button onClick="history.back()" value="Back">
<input type=button onClick="history.forward()" value="Forward">
<a href="../WordList.en.html">Jump to Vocabulary</a>
</p>
 
</div>
 
<!-- AUTOINCLUDE START "Page/Footer.en.ihtml" DO NOT REMOVE -->
<!-- ============== FOOTER ============== -->
<div class="Footer">
<script type="text/javascript">
<!--
SetRelativePath("../../../../");
DrawFooter();
// -->
</script>
<noscript>
<p><b> JavaScript is required for including of the footer </b></p>
</noscript>
</div>
<!-- AUTOINCLUDE END -->
 
</body>
</html>