Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.lang.asm.x86    |    Ahh, the lost art of x86 assembly    |    4,675 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 4,379 of 4,675    |
|    wolfgang kern to luser...@nospicedham.gmail.com    |
|    Re: shorter code to print a 16bit number    |
|    30 Jul 21 14:53:56    |
      From: nowhere@nospicedham.never.at              On 30.07.2021 07:11, luser...@nospicedham.gmail.com wrote:       > I wrote this machine code to trace the LIT word in my forth interpreter.       > Is it possible to tighten up this code? It's trying to print a 16bit signed       > integer (ignoring INT_MIN) left to right with no leading zeros.              I'm sure that thjis could be made much faster and shorter too :)              > This is assembly code, but I hope you'll forgive my ideosyncratic syntax.       > The operands map left to right to the reg and reg/mem fields into the       > mod-reg-reg/mem byte and the opcodes target the "to" form (direction       > field = 1), eg. in "MOV(,R,BX,AX)", BX is the dest, AX is the source, the       > R is needed to select register-to-register mode (the mod field). The empty       > first argument is for tweaks to the opcode which could be F (clear the       > direction field by subtracting 2) or BYTE (clear the word field by       subtracting 1).       >       > It tests each digit for zero where it jumps over the int 10h call except       > the last digit.              to speed it up you can use reciprocal MUL instead if DIV       tried to fall through instead of jump over ?       better would be a buffer and only a single write to screen.              > It occurs to me that the DIV instruction has a mod field. So that means       > the divisor could be register indirect, right? like through SI or BX, maybe?       > Then it could probably be rolled up in a loop, right? Sorry if I'm jumping       > the gun asking for help before exerting the requisite effort.              don't you use them already? DIV(R,CX)                     > CODE(lit, lit, LODS, PUSH(AX)       >       > #ifdef TRACE       >       > , MOV(,R,BX,AX), OR(,R,BX,BX), JGE,7, MOVI(AX,0x0E00+'-'),       INT(10), NEG(R,BX),       >       > MOV(,R,AX,BX), XOR(,R,DX,DX), MOVI(CX,10000), DIV(R,CX),       >       > OR(,R,AX,AX), JZ,6, MOVBI(AH,0x0E), ADDAL(48), INT(10),       >       > MOV(,R,AX,DX), XOR(,R,DX,DX), MOVI(CX,1000), DIV(R,CX),       >       > OR(,R,AX,AX), JZ,6, MOVBI(AH,0x0E), ADDAL(48), INT(10),       >       > MOV(,R,AX,DX), MOVBI(CL,100), XOR(BYTE,R,CH,CH), BYTE+DIV(R,CL),       >       > MOV(BYTE,R,DL,AH),       >       > OR(BYTE,R,AL,AL), JZ,6, MOVBI(AH,0x0E), ADDAL(48), INT(10),       >       > MOV(BYTE,R,AL,DL), XOR(BYTE,R,AH,AH), MOVBI(CL,10), BYTE+DIV(R,CL),       >       > MOV(BYTE,R,DL,AH),       >       > OR(BYTE,R,AL,AL), JZ,6, MOVBI(AH,0x0E), ADDAL(48), INT(10),       >       > MOVBI(AH,0x0E), MOV(BYTE,R,AL,DL), ADDAL(48), INT(10),       >       > MOVI(AX,0x0E00+' '), INT(10)       >       > #endif              I'm not familiar with this syntax, but I see many equal lines before the       too many INT 10.              F7 F0 ...F7 F7 and F6 F7..F6 F7 are indeed DIV by reg       same for the IDIV groups F7 F8...       __       wolfgang              --- SoupGate-Win32 v1.05        * Origin: you cannot sedate... all the things you hate (1:229/2)    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca