Free2Code
 
Time: 2009-01-05, 10:53pm
dec to hex
Subject: dec to hex  ·  Posted: 2006-10-12, 09:23pm
Rank: ? (4)
Member #: 28621
can anyone help me to convert dec to hex in assembler with 2 digit inputs from the user? please help i need it badly. thank you in advance

 
  Reply to this ·  Post link ·  Top
Subject: Re: dec to hex  ·  Posted: 2006-10-13, 03:36am
Rank: ? (4821)
Member #: 3416
what part are you stuck on?

my mind is like a steel trap! it only hangs on to the big stuff. visit my forums at track7.org
 
  Reply to this ·  Post link ·  Top
This post has been removed by the author
 
  Top
Subject: Re: dec to hex  ·  Posted: 2006-10-13, 12:25pm
Rank: ? (4)
Member #: 28621
specifically converting dec to hex...cant display the output..

 
  Reply to this ·  Post link ·  Top
Subject: Re: dec to hex  ·  Posted: 2006-10-13, 10:30pm
Rank: ? (5)
Member #: 28723
Hi,

i just did a conversion for dec<->hex, maybe u can find some hints.
Basically i stored the entered value in a variable ( by multiplying each number with the right power ( *10/16 for hex)
Then i display the sum byte for byte by dividing with the right divisor ( again 10 for dec,16 (not h!) for hex)

greetz,

olli

Code:
  1. model tiny
  2. .data?
  3. estr            db 10 dup(?)
  4. e_len           dw ?
  5. hex_mode db ?
  6. summe dw ?
  7. .data
  8. msg_start db 13,10,'Enter value ( nnh for hex value, Enter=Ende) !',13,10,'$'
  9. msg_summe db 13,10,' equals: $'
  10. msg_hex db ' decimal ',13,10,'$'
  11. msg_dec db ' h',13,10,'$'
  12. msg_ende db 13,10,'Program ended normally',13,10,'$'
  13. .code
  14.        
  15. ; konstanten
  16. dos equ 021h
  17. print macro meldung
  18.         lea dx, meldung
  19.         mov ah,09
  20.         int dos
  21. endm
  22. putc macro
  23.         mov ah,02
  24.         int dos
  25. endm
  26. .startup
  27. b00_10:
  28.         call b10_read_input
  29.         cmp e_len,0
  30.         je main_ende
  31.         call b20_calc
  32.         call b40_print_summe
  33.         loop b00_10
  34. main_ende:
  35.         print msg_ende
  36. .exit
  37. b40_print_summe:
  38.         print msg_summe
  39.         mov ax,summe
  40.         xor bx,bx
  41.         xor cx,cx
  42.         mov bl,10
  43.         cmp hex_mode,1
  44.         je b40_10
  45.         mov bl,16
  46. b40_10:
  47.         inc cx
  48.         xor dx,dx
  49.         div bx
  50.         push dx
  51.         cmp ax,0
  52.         jne b40_10
  53. b40_20:
  54.         pop dx
  55.         add dl,30h ; auf asci erweitern
  56.         cmp dl,'9'
  57.         jna b40_25
  58.         add dl,27h
  59. b40_25:
  60.         putc
  61.         loop b40_20
  62.         cmp hex_mode,1
  63.         jne b40_30
  64.         print msg_hex
  65.         jmp b40_35
  66. b40_30:
  67.         print msg_dec
  68. b40_35:
  69. ret
  70. ;----------------------------------------------
  71. ; eingabe in summe umrechnen
  72. ; je stelle mal x 10 bzw.  x 16 fuer hexa
  73. ;----------------------------------------------
  74. b20_calc:
  75. mov summe,0
  76. lea si,estr
  77. mov bx,e_len
  78. b20_10:
  79.         mov ax,summe
  80.         cmp hex_mode,1 ; hex modus ?
  81.         je b20_15
  82.         mov cl,3
  83.         shl ax,cl
  84.         add ax,summe ;( x*8+x*2=x*10 
  85.         add ax,summe
  86.         jmp b20_17
  87. b20_15:
  88.         mov cl,4 ; fuer hexa * 2^4=*16
  89.         shl ax,cl
  90. b20_17:
  91.         mov summe,ax
  92.         mov al,[si]
  93.         sub al,30h ; asci->wert umrechnen
  94.         cmp al,10 ; wenn > 10 ists hexa a-f
  95.         jb b20_20
  96.         sub al,27h ;(49-39=10) 'a' -> 10d  umwandeln
  97. b20_20:
  98.         xor ah,ah
  99.         add summe,ax
  100.         inc si
  101.         dec bx
  102.         jnz b20_10
  103. ret
  104. ;------------------------------------------
  105. ; eingabe einlesen
  106. ;------------------------------------------
  107. b10_read_input:
  108.         print msg_start
  109.         mov hex_mode,0
  110.         mov e_len,0
  111.         lea di,estr
  112. b10_20:
  113.         mov ah,01       ; 1 byte einlesen
  114.         int dos
  115.         cmp al,13
  116.         je b10_30
  117.         inc e_len
  118.         mov [di],al
  119.         inc di  ; position to next character
  120.         jmp b10_20 ;naechstes zeichen einlesen
  121. b10_30:
  122.         dec di
  123.         mov al,[di]
  124.         cmp al,'h'      ; h last character ?
  125.         jne b10_50
  126.         mov hex_mode,1  ; hex modus setzen
  127.         dec e_len ; "h" sub 1 from length for "h"
  128. b10_50:
  129. ret
  130. end


» Post edited 2006-10-13, 10:32pm by kermit.

 
  Reply to this ·  Post link ·  Top
Subject: Re: dec to hex  ·  Posted: 2006-10-17, 08:20pm
Rank: ? (4)
Member #: 28621
im using tasm, pls convert it into tasm.. thank you

 
  Reply to this ·  Post link ·  Top
Subject: Re: dec to hex  ·  Posted: 2006-10-21, 09:14pm
Rank: ? (119)
Member #: 28292
Hm.. As far as I know Tasm supports Masm syntax

 
  Reply to this ·  Post link ·  Top

Pages: 1

Please login or register to post a reply.

icons