﻿ ASM Optimized routines
23 May, 2013, 11:44:40
 OmnomIRC You must Register, be logged in and have at least 40 posts to use this shout-box! If it still doesn't show up afterward, it might be that OmnomIRC is disabled for your group or under maintenance.Note: You can also use an IRC client like mIRC, X-Chat or Mibbit to connect to an EFnet server and #omnimaga.

 Pages: 1 2 [3] 4 5   Go Down
 Author Topic: ASM Optimized routines -  (Read 5576 times) 0 Members and 1 Guest are viewing this topic.
calc84maniac
Epic z80 roflpwner
Coder Of Tomorrow
LV11 Super Veteran (Next: 3000)

Offline

Gender:
Last Login: 20 May, 2013, 21:27:24
Date Registered: 28 August, 2008, 05:09:05
Location: Right behind you.
Posts: 2735

Total Post Ratings: +373

 « Reply #30 on: 01 December, 2011, 18:39:56 » 0

I took a shot at optimizing it some more, I'm not sure if it works, but I think it should.

 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 ;===============================================================HL_SDiv_BC:;===============================================================;Performs HL/BC;Speed:   1168 to 1318 cycles depending on how many set bits in the result;         add 19 if HL is negative;         add 19 if BC is positive;         add another 28 if only one is negative ;Size:    54 bytes;         **31 bytes larger than the regular HL_Div_BC;Inputs:;     HL is the numerator;     BC is the denominator;Outputs:;     HL is the quotient;     DE is the remainder;     BC = -abs(BC);===============================================================     ld a,h     xor b     push afabsHL:     add hl,hl     jr nc,negabsBC     xor a \ sub l \ ld l,a     sbc a,a \ sub h \ ld h,anegabsBC:     bit 7,b     jr nz,\$+8     xor a \ sub c \ ld c,a     sbc a,a \ sub b \ ld b,a       ex de,hl       xor a       ld h,a       ld l,a       ld a,15Div_Loop_1:         rl e \ rl d         adc hl,hl         add hl,bc         jr c,\$+4          sbc hl,bc         dec a         jr nz,Div_Loop_1       ex de,hl       adc hl,hl       pop af \ ret p     xor a \ sub l \ ld l,a     sbc a,a \ sub h \ ld h,a     ret

Edit: Just realized I needed to clear the carry before the loop. My fix renders Xeda's ld hl,0 comment moot though, sorry
 « Last Edit: 01 December, 2011, 19:10:37 by calc84maniac » Logged

"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman
 Pages: 1 2 [3] 4 5   Go Up