OpenCores
URL https://opencores.org/ocsvn/ssbcc/ssbcc/trunk

Subversion Repositories ssbcc

[/] [ssbcc/] [trunk/] [lib/] [9x8/] [char.s] - Blame information for rev 2

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 sinclairrf
; Copyright 2013, Sinclair R.F., Inc.
2
;
3
; Character manipulation functions
4
 
5
.IFNDEF C__INCLUDED__CHAR_S__
6
.constant C__INCLUDED__CHAR_S__ 0
7
 
8
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9
;
10
; Conversion to and from hex.
11
;
12
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13
 
14
; Convert a byte to its 2-digit hex representation with the digit for the most
15
; significant nible at the top of the data stack.
16
; ( u - u_hex_lsn u_hex_msn )
17
.function char__byte_to_2hex
18
  ; ( u - u u_hex_low )
19
  dup 0x0F .call(char__nibble_to_hex,&)
20
  ; ( u u_hex_low - u_hex_low u_hex_high )
21
  swap 0>> 0>> 0>> .call(char__nibble_to_hex,0>>)
22
  .return
23
 
24
; Convert a nibble between 0x00 and 0x0F inclusive to it hex digit.
25
; ( u - u_hex_n )
26
.function char__nibble_to_hex
27
  0x09 over - 0x80 & 0<> ${ord('A')-ord('9')-1} & + '0' .return(+)
28
 
29
; Convert two hex digits to their byte value.  Return 0x00 on success and 0xFF
30
; on failure.
31
; ( u_hex_lsn u_hex_msn - u f )
32
.function char__2hex_to_byte
33
  ; convert the msn to its position and save the error indication
34
  ; ( u_hex_lsn u_hex_lsn - u_hex_msn u_msn ) r:( - f_msn )
35
  .call(char__hex_to_nibble) >r <<0 <<0 <<0 <<0
36
  ; ( u_hex_lsn u_msn - u ) r:( f_msn - f_lsn f_msn )
37
  ; convert the lsn to its position, save the error indication, and combine the two nibble conversions
38
  .call(char__hex_to_nibble,swap) >r or
39
  ; compute the return status and return
40
  ; ( u - u f ) r:( f_lsn f_msn - )
41
  r> r> .return(or)
42
 
43
; Convert a single hex digit to its nibble value.  Return 0x00 on success and
44
; 0xFF on failure.
45
; ( u_hex_n - u f )
46
.function char__hex_to_nibble
47
  dup        0x80 & .jumpc(error)
48
  dup '0'  - 0x80 & .jumpc(error)
49
  '9' over - 0x80 & .jumpc(not_value_0_to_9) '0' - .return(0)
50
  :not_value_0_to_9
51
  dup 'A'  - 0x80 & .jumpc(error)
52
  'F' over - 0x80 & .jumpc(not_value_A_to_F) ${ord('A')-10} - .return(0)
53
  :not_value_A_to_F
54
  dup 'a'  - 0x80 & .jumpc(error)
55
  'f' over - 0x80 & .jumpc(error) ${ord('a')-10} - .return(0)
56
  :error .return(0xFF)
57
 
58
.ENDIF ; C__INCLUDED__CHAR_S__

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.