Quantcast
Viewing all articles
Browse latest Browse all 5

Answer by Shift_Left for Ubuntu 18.04.3 LTS get terminal columns and rows NASM

Edward wrote:

Jumps often take longer, and jumps without explicitly named targets are a recipe for future frustration.

Yes, I remember the days when I used to spend hours just for that very reason, but it's become such a habit now, that whenever I anticipate a change, if there isn't an explicit reference I look up in code to see where that register was initialized. What I plan on doing in the future is commenting as such;

    cld                         ; Just to be sure indices auto increment.; RDX has been set to winsize structure by previous ; sys_ioctl call to TIOCGWINSZ, as has RAX been set to zero.    cmp     word [edx+2], 132   ; Expect a minimum 132 columns    adc      al, al    shl      al, 1              ; Move to next bit position    cmp     byte [edx], 43      ; Expect a minimum 43 rows    adc      al, 0; Save new data where ws_xpixel was and erase any extraneous; data @ ws_ypixel    mov     [edx+4], eax        ; Overwrite ws_xpixel & ws_ypixel.

I think this would be a step in the right direction for those reading my code that they wouldn't have to search all over. This example saves another 5 bytes using implicit references instead of explicit.


A significant size and by that extension speed saving was realized with this change.

   22:        89 c2          mov    edx,eax   24:        66 ad          lods   ax,WORD PTR ds:[rsi]   26:        66 83 e8 2b    sub    ax,0x2b   2a:        79 03          jns    2f <_start+0x2f>   2c:        80 ca 01       or     dl,0x1   2f:        66 ad          lods   ax,WORD PTR ds:[rsi]   31:        66 2d 84 00    sub    ax,0x84   35:        79 03          jns    3a <_start+0x3a>   37:        80 ca 02       or     dl,0x2   3a:        89 16          mov    DWORD PTR [rsi],edx   0x3c - 0x22 = 26 bytes

versus

    20:    66 67 81 7a 02 84 00     cmp    WORD PTR [edx+0x2],0x84    27:    10 c0                    adc    al,al    29:    d0 e0                    shl    al,1    2b:    67 80 3a 2b              cmp    BYTE PTR [edx],0x2b    2f:    14 00                    adc    al,0x0    31:    67 89 42 04              mov    DWORD PTR [edx+0x4],eax   0x35 - 0x20 = 21 bytes

Had I used explicit references, then the size saving would have been completely negated, but speed is still significantly improved in either context.


Viewing all articles
Browse latest Browse all 5

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>