8086 Assembly (TASM): Displaying an ASCII character value as HEX

前端 未结 2 606
死守一世寂寞
死守一世寂寞 2021-02-04 23:12

** Edited for clarification and \"cleaner\" code.

I\'m trying to accept a character from the keyboard (any character) and convert it\'s ASCII value to hex, then display

2条回答
  •  再見小時候
    2021-02-04 23:35

    Write your program in C or some other language first. dont use the languages libraries, for example dont use printf("%x\n",number) to display hex, but take the number do the repeated divide by 10s as you suggest, saving them somewhere. Now remember the remainders (modulo) from dividing by ten is something between 0-9 to display this somewhere in ascii you need to add 0x30 as you mentioned. 123 becomes 12 remainder 3, then 12 becomes 1 remainder 2, and 1 becomes 0 remainder 1, 1+0x30 = 0x31 display that 2+0x30 becomes 0x32 display that, 3+0x30 becomes 0x33 display that.

    hex is no different, the base is 16 not 10. As vhallac mentions though you can mask and shift instead of using the divide operator.

    Once you have the "program" working in C or some other language, at a low level using basic operations (add, sub, divide, shift, and, or, etc) then re-write that code in assembly language.

    Eventually you may get to the point where you dont need to prove out your program in some other language and start with asm.

提交回复
热议问题