VB6 Pcode - For LoopsAuthor: David Zimmer Date: 03.26.20 - 11:08am First the video version: I would eventually like to document each opcode. Below is a sample of the For loop family of opcodes. For Loops Each different data type has its own opcode for looping. Additionally there are special opcodes foreach and when the for step increment is something other than 1. Several flavors of ExitFor opcodes also exist. Byte stream length is typically 5, but ForEach variants require 7 bytes. For loop setup also requires several args on the stack that are consumed when the opcode hits. There are three main types of for loop. Normal, For Each, and For Step Here is an example of a For step loop being initilized Dim b As Byte For b = &H22 To &H26 Step 2 401630 Module1.Sub Main: ... 401686 F4 22 LitI2_Byte 0x22 'start value pushed onto stack 401688 FC0D CUI1I2 'convert 2 byte integer to unsigned byte (check value bounds) 40168A 04 66FF FLdRfVar var_9A 'counter variable address pushed onto stack 40168D F4 26 LitI2_Byte 0x26 'loop end value pushed onto stack 40168F FC0D CUI1I2 401691 F4 02 LitI2_Byte 2 'step increment pushed onto stack 401693 FC0D CUI1I2 401695 FE6A 1CFF8300 ForStepUI1 var_E4 loc_4016B3 'var_E4 = loop control structure, loc_4016B3 = address at end of loop 40169B FCE0 66FF FLdUI1 var_9A 'current loop counter value ... 4016AA 04 66FF FLdRfVar var_9A 'push counter var address onto stack 4016AD FE80 1CFF6B00 NextStepUI1 var_E4 loc_40169B 'loc_40169B = instruction to jump to to restart next loop iter When ForStepUI1 opcode runs, it will consume the 4 args passed to it on the stack. In our example var_e4 given in the byte stream holds the loop control structure struct ForStepUI1LoopControl{ step_increment as byte endValue as byte } This struct element sizes is based on which type of For loop it is, ie I2 integer, I4 long etc. struct ForStepI2LoopControl{ step_increment as integer endValue as integer } 401630 Module1.Sub Main: 401630 F5 00000000 LitI4 0x0 401635 F5 FFFFFFFF LitI4 0xFFFFFFFF 40163A 3A 54FF0000 LitVarStr var_AC str_401270=',' 40163F 4E 44FF FStVarCopyObj var_BC 401642 04 44FF FLdRfVar var_BC 401645 1B 0100 LitStr str_401258='1,2,3,4,5' 401648 04 34FF FLdRfVar var_CC 40164B 0A 02001400 ImpAdCallFPR4 rtcSplit 401650 04 34FF FLdRfVar var_CC 401653 FF36 0820 StAryVar 0x2008 (Bstr | ARRAY) 401657 59 30FF PopTmpLdAdStr var_D0 40165A 04 68FF FLdRfVar var_98 40165D FF02 StAryCopy 40165F 36 [8 bytes] FFreeVar var_BC var_CC 401666 6C 68FF ILdRf [var_98] 401669 04 6CFF FLdRfVar var_94 40166C FE76 28FF08008300 ForEachAryVar var_D8 0x8 loc_4016B3 401674 04 6CFF FLdRfVar var_94 401677 55 CI2Var 401678 70 64FF FStI2 [var_9C] 40167B F4 01 LitI2_Byte 1 40167D FC0D CUI1I2 40167F 04 66FF FLdRfVar var_9A 401682 F4 04 LitI2_Byte 4 401684 FC0D CUI1I2 401686 F4 02 LitI2_Byte 2 401688 FC0D CUI1I2 40168A FE6A 24FF7800 ForStepUI1 var_DC loc_4016A8 401690 FCE0 66FF FLdUI1 var_9A 401694 FC14 CI2UI1 401696 F4 04 LitI2_Byte 4 401698 C6 EqI2 401699 1C 6F00 BranchF loc_40169F 40169C 1E 7800 Branch loc_4016A8 40169F loc_40169F: ; 401699 40169F 04 66FF FLdRfVar var_9A 4016A2 FE80 24FF6000 NextStepUI1 var_DC loc_401690 4016A8 loc_4016A8: ; 40169C 4016A8 04 6CFF FLdRfVar var_94 4016AB FE77 28FF08004400 NextEachAryVar var_D8 0x8 loc_401674 4016B3 14 ExitProcI4 Comments: (0) |
![]() ![]() About Me More Blogs Main Site
|
||||||||||||||||||||