;*******************************************************************************
; Input: unpacked BCD in tenk:thou:hund:tens:ones
;Output: 16 bit binary in hi:lo
; Size: 35 instructions
;Timing: 3+34+3=40 instruction cycles
;
; Notes:
;1) if input is higher than 65535 output is meaningless
;2) algorithm synopsis:
;
;> dec2bin([1 10 100 1000 1e4], 16)
;ans =
;0000000000000001
;0000000000001010
;0000000001100100
;0000001111101000
;0010011100010000
;
;Or coded in three levels ('+' represents +1, '-' represents -1):
;000000000000000+ * ones +
;000000000000+0+0 * tens +
;000000000++00+00 * hund +
;00000+0000-0+000 * thou +
;00+0+00-000+0000 * tenk
;
;bin = (((tens+thou+tenk*256)*2+
; hund+hund*16+thou*256)*2+
; tens+hund*16-thou*16+tenk*16*256)*2+
; ones+tenk*16-tenk*256
;
;January 22, 2001 by Nikolai Golovchenko
;*******************************************************************************
dec2bin16
mov W, tens
add W, thou
mov lo, W
add lo, W
mov W, <<tenk
mov hi, W
mov W, <>hund
add W, hund
add lo, W
mov W, thou
add hi, W
rl lo
rl hi
mov W, <>hund
add W, tens
add lo, W
mov W, <>tenk
snc
or W, #$01
add hi, W
mov W, <>thou
sub lo, W
sc
dec hi
clc
rl lo
rl hi
mov W, <>tenk
add W, ones
add lo, W
mov W, tenk
snc
mov W, --tenk
sub hi, W
retp
;*******************************************************************************
| file: /Techref/scenix/lib/math/radix/dec2bin16.htm, 1KB, , updated: 2004/6/10 14:40, local time: 2025/10/25 01:39,
owner: NG--944,
216.73.216.22,10-3-83-201:LOG IN
|
| ©2025 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions? <A HREF="http://www.piclist.com/techref/scenix/lib/math/radix/dec2bin16.htm"> Unpacked BCD to 16 bit binary conversion</A> |
| Did you find what you needed? |
|
o List host: MIT, Site host massmind.org, Top posters @none found - Page Editors: James Newton, David Cary, and YOU! * Roman Black of Black Robotics donates from sales of Linistep stepper controller kits. * Ashley Roll of Digital Nemesis donates from sales of RCL-1 RS232 to TTL converters. * Monthly Subscribers: Gregg Rew. on-going support is MOST appreciated! * Contributors: Richard Seriani, Sr. |
|
The Backwoods Guide to Computer Lingo |
.