Convert hex character to decimal equivalent in MIPS -
How can I take a single ASCII character and convert it to my decimal equivalent in MIP?
Do I need some conditions to reduce a certain amount to represent my decimal with ASCII code?
file hextodec.S Test run #include & lt; Stdio.h & gt; / * * A ASCII changes its decimal equivalent in four. -1 return on error * * / extenacit hexodec (four * c); Int main (int argc, char ** argv) {int i = 0; Four digits [] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A' B ',' C ',' D ',' F '}; For (; i & lt; 16; i ++) {printf ("% c \ t% d \ n", number [i], hexodec (numeral + i)); } Return 0; }
#include & lt; Mips / regdef.h & gt; / * Int hexododic (four * C) * First (and only) logic is set in register A0. * Return value is set in register v0. * Calling ceremony has ignored the conference. * / .text .globl hextodec .align2 .ent hextodec hextodec: lbu t0,0 (a0) #load byte logic li t1,0x30 li t2,0x39 andi t1, t1,0x000000ff # For the term for comparison, the Andy T2 , T0.20x000000 FFTTTT, T1, Error #Terror if 0x30 BGT T, T2, less than 0x39 than DOhex, between A-F ADUD T, T, -0x30 # OK, 48 and 55 Test for Subtact 48. B Returns Dhex: LiT0x41LiT2.0x4AndyT1, TATX x000000FF # Cost and T2 for the term for comparison, T20x000000ff / * Byte between 65 and 70 ? * / Bltu t0, t1, Error # Terror if 0x41 BGT T is less than T2, Error # Terror is greater than 0x46: addiu t0, t0, - hex four ('a' - 'f') b return 0x37 #subtract 55 Error: ADUU T, Zero, -1 # Return -1 Return to: v0, t0 #move Return value v0 to register jr ra .end hextodec
root @: ~ / Stackoverflow #. / Hextodec 0 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 A 10 B11C12D13E14F15 Root @: ~ / flow on stack #
Comments
Post a Comment