flat assembler
Message board for the users of flat assembler.
  
       
      Index
      > High Level Languages > [solved]how casting a *dword to *word works? | 
  
| Author | 
  | 
              
| 
                  
                   DimonSoft 22 Feb 2018, 22:36 
                  vivik wrote: I need to do something like this: Since the question is asked in “High Level Languages” section of the forum, I’ll ask what language do you want to use.  | 
              |||
                  
  | 
              
| 
                  
                   revolution 23 Feb 2018, 00:10 
                  dword == long I presume? And word == short?
 
                  
                I think a good way to see what your compiler does with that code it to build it and then debug/disassemble it to see what it is doing.  | 
              |||
                  
  | 
              
| 
                  
                   rugxulo 23 Feb 2018, 05:15 
                  Perhaps union? 
                  
                 | 
              |||
                  
  | 
              
| 
                  
                   vivik 23 Feb 2018, 06:29 
                  This worked:
 
                  
                *(unsigned short*)g_texture_thumb_cursor = 0xF1F2; g_texture_thumb_cursor = (DWORD*)((unsigned short*)g_texture_thumb_cursor + 1); Not very readable, huh? Had to google "void pointer increment".  | 
              |||
                  
  | 
              
| 
                  
                   vivik 23 Feb 2018, 06:46 
                  I think I'll use these types:
 
                  
                https://msdn.microsoft.com/en-us/library/windows/desktop/aa383751(v=vs.85).aspx BYTE WORD DWORD INT8 INT16 INT32 UINT8 UINT16 UINT32  | 
              |||
                  
  | 
              
| 
                  
                   DimonSoft 23 Feb 2018, 06:59 
                  vivik wrote: I think I'll use these types: Might not be a good idea in terms of portability.  | 
              |||
                  
  | 
              
| 
                  
                   revolution 23 Feb 2018, 07:13 
                  vivik wrote: This worked: Code: g_texture_thumb_cursor dw 0xF1F2,0 inc dword[g_texture_thumb_cursor]  | 
              |||
                  
  | 
              
| 
                  
                   vivik 24 Feb 2018, 08:24 
                  Actually, it's much more simple if I just use char*.
 
                  
                char* pointer = (char*)malloc(1024); *(INT32*)pointer = 1; pointer += 4; *(INT32*)pointer = 2; pointer += 4; *(UINT16*)pointer = 1; pointer += 2; *(UINT16*)pointer = 2; pointer += 2; *(UINT16*)pointer = 3; pointer += 2; *(UINT16*)pointer = 4; pointer += 2;  | 
              |||
                  
  | 
              
| 
                  
                   DimonSoft 24 Feb 2018, 09:39 
                  vivik wrote: Actually, it's much more simple if I just use char*. Why not define a struct and cast the pointer?  | 
              |||
                  
  | 
              
| 
                  
                   vivik 24 Feb 2018, 13:45 
                  >Why not define a struct and cast the pointer?
 
                  
                Indeed why... I can merge the last four UINT16 into one struct at least. (Can't make everything into one structure, because the second INT32 is the amount of those UINT16.) I need to compare the assembly, later.  | 
              |||
                  
  | 
              
< Last Thread | Next Thread >  | 
    
Forum Rules: 
  | 
    
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.