<!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> words/slashmod.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> words/slashmod.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>; ( n1 n2 -- rem quot) Arithmetics; R( -- ); signed division n1/n2 with remainderVE_SLASHMOD:.db $04, "/mod",0.dw VE_HEAD.set VE_HEAD = VE_SLASHMODXT_SLASHMOD:.dw PFA_SLASHMODPFA_SLASHMOD:movw temp2, toslld temp0, Y+ld temp1, Y+mov temp6,temp1 ;move dividend High to sign registereor temp6,temp3 ;xor divisor High with sign registersbrs temp1,7 ;if MSB in dividend setrjmp PFA_SLASHMOD_1com temp1 ; change sign of dividendcom temp0subi temp0,low(-1)sbci temp1,high(-1)PFA_SLASHMOD_1:sbrs temp3,7 ;if MSB in divisor setrjmp PFA_SLASHMOD_2com temp3 ; change sign of divisorcom temp2subi temp2,low(-1)sbci temp3,high(-1)PFA_SLASHMOD_2: clr temp4 ;clear remainder Low bytesub temp5,temp5;clear remainder High byte and carryldi temp7,17 ;init loop counterPFA_SLASHMOD_3: rol temp0 ;shift left dividendrol temp1dec temp7 ;decrement counterbrne PFA_SLASHMOD_5 ;if donesbrs temp6,7 ; if MSB in sign register setrjmp PFA_SLASHMOD_4com temp1 ; change sign of resultcom temp0subi temp0,low(-1)sbci temp1,high(-1)PFA_SLASHMOD_4: rjmp PFA_SLASHMODmod_done ; returnPFA_SLASHMOD_5: rol temp4 ;shift dividend into remainderrol temp5sub temp4,temp2 ;remainder = remainder - divisorsbc temp5,temp3 ;brcc PFA_SLASHMOD_6 ;if result negativeadd temp4,temp2 ; restore remainderadc temp5,temp3clc ; clear carry to be shifted into resultrjmp PFA_SLASHMOD_3 ;elsePFA_SLASHMOD_6: sec ; set carry to be shifted into resultrjmp PFA_SLASHMOD_3PFA_SLASHMODmod_done:; put remainder on stackst -Y,temp5st -Y,temp4; put quotient on stackmovw tosl, temp0jmp_ DO_NEXT</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>