SOS!!! I have a question here, about division. Here's what my tutorial says: For signed division, set AH or DX to 0 (0000h) if it is a positive number and set them to -1 (FFFFh) if the number is negative. This is just standard sign extension that was covered in the chapter on numbers. Fortunately for us, Intel has provided instructions which do the sign extension for us. CBW (convert byte to word) correctly extends the signed number in AL through AH:AL. CWD (convert word to double) correctly extends the signed number in AX through DX:AX. So, what is sign extension and why is it needed?? What's the purpose of extending a byte into a word or even a double word? Under what circumstances do we need to do this? One more question. What do they actually mean when they say DX:AX registers? As in for multiplication, the result of the word multiplication is stored in DX:AX. What does it actualli mean??? The program that my tutorial has created for me show the values on the different registers and under word multiplication, if the result is greater than 65535, there's funny values on DX and AX. This is the program code:

; put name here

; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
STACKSEG    SEGMENT   STACK  'STACK'

             dw     500h  dup (?)

STACKSEG    ENDS
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
DATASTUFF    SEGMENT   PUBLIC  'DATA'

       ; 1 = signed, 2 = unsigned, 3 = binary
       ; 4 = hex, 5 = ascii 
       ; 90h = signed, A0h = unsigned, B0h = binary
       ; C0h = hex, D0h = ascii 

ax_byte      db  2
bx_byte      db  2
cx_byte      db  2
dx_byte      db  2
si_byte      db  2
di_byte      db  2
bp_byte      db  2
sp_byte      db  2

; + + + + + + + + + + + + + + + START DATA BELOW THIS LINE
answer1 dw ?
answer2 dw ?
; + + + + + + + + + + + + + + + END DATA ABOVE THIS LINE

DATASTUFF    ENDS
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CODESTUFF    SEGMENT   PUBLIC  'CODE'

       ; **************  ASMHELP.OBJ  INFO

       EXTRN  show_regs:NEAR , show_regs_and_wait:NEAR
       EXTRN  set_reg_style:NEAR , set_count:NEAR
       EXTRN  set_blue:NEAR , get_continue:NEAR
       EXTRN  set_timer:NEAR, kill_timer:NEAR
       
       EXTRN  get_num:NEAR ,            print_num:NEAR 
       EXTRN  get_string:NEAR ,         print_string:NEAR
       EXTRN  get_ascii_byte:NEAR  ,    print_ascii_byte:NEAR
       EXTRN  get_ascii:NEAR  ,         print_ascii:NEAR
       EXTRN  get_hex_byte:NEAR ,       print_hex_byte:NEAR
       EXTRN  get_hex:NEAR ,            print_hex:NEAR 
       EXTRN  get_binary_byte:NEAR ,    print_binary_byte:NEAR
       EXTRN  get_binary:NEAR ,         print_binary:NEAR
       EXTRN  get_bcd:NEAR   ,          print_bcd:NEAR
       
       EXTRN  get_signed_byte:NEAR ,    print_signed_byte:NEAR
       EXTRN  get_unsigned_byte:NEAR ,  print_unsigned_byte:NEAR
       EXTRN  get_signed:NEAR ,         print_signed:NEAR
       EXTRN  get_unsigned:NEAR ,       print_unsigned:NEAR 
       EXTRN  get_signed_4byte:NEAR ,   print_signed_4byte:NEAR
       EXTRN  get_unsigned_4byte:NEAR , print_unsigned_4byte:NEAR
       EXTRN  get_signed_8byte:NEAR ,   print_signed_8byte:NEAR
       EXTRN  get_unsigned_8byte:NEAR , print_unsigned_8byte:NEAR

       ; **************  END ASMHELP.OBJ  INFO
          
       ASSUME cs:CODESTUFF, ds:DATASTUFF

; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

start: push  ds               ; set up for return
       sub   ax,ax
       push  ax

       mov   ax, DATASTUFF    ; load ds
       mov   ds,ax

; + + + + + + + + + + + + + + + START CODE BELOW THIS LINE

    mov cx, 0   ; clear cx for visual effect

outer_loop:
    ;unsigned multiplication
    mov ax_byte, 0A2h   ; half regs, unsigned
    mov bx_byte, 0A2h   ; half regs, unsigned
    lea ax, ax_byte
    call set_reg_style

    mov ax, 0   ;clear regs
    mov bx, 0   
    mov dx, 0
    call show_regs

    call get_unsigne
Posted on 2001-06-02 13:56:00 by JCL
In assembly everything is data (numbers - code can be data, data can be code - all is numbers). You must choose what is valid data, and what is invalid data. For example, when a program starts you have no idea what the computer was doing before the program was run. So, you assume that all the registers are invalid - you don't care what was there before. In your own programs, you can know what happens from instruction to instruction. So, you know what to expect - you know what data is valid. When you code an algorithm you decide what the external dependancies are (this would be a good thing to document, and this becomes the interface to the algorithm). The internal dependancies are determined by the choice of algorithm (only document these if you want to make editing the code later easier). LEA is a powerful instruction because it can do a MUL, and two ADDs in one instruction! LEA stands for Load Effective Address and that is it's purpose. Here is an example:

    lea ebx, MyPointerTable
    lea eax, [64 + ebx + ecx*4]
Posted on 2001-06-05 14:52:00 by bitRAKE
The LEA instruction doesn't pair, and can be slow. Unless your using the full functionality of the instruction, it better to use other instructions.
Posted on 2001-06-06 12:05:00 by bitRAKE
OK, I'll not send u the tutorial then. But it doesn't specified anything much. Just that if u feel like it, u can send a 10 dollar cheque to the author(that's what he said!) Hmm. How much does speed matters in assembly? And how we know which instruction is slow and which is fast? So, LEA is slow and should not be used unless needed. BUt how slow is slow and how fast is fast?
Posted on 2001-06-07 13:43:00 by JCL
Ok, I have deleted most of my posts alreadi. Took some time there. So, I just learn the basics now and dun bother abt speed now?
Posted on 2001-06-10 11:43:00 by JCL

 http://www.masm32.com/Win32Chat.exe

 JCL, download that, that allows us to chat in REAL-TIME


Posted on 2001-06-10 11:51:00 by disease_2000
OK, I;m downloading it but does it works like icq or wat? WHen r u online most of the time?
Posted on 2001-06-11 13:24:00 by JCL
That tutorial is pretty old, I reckon. mul something16 multiplies ax by something16, which can be a register or memory, but not a constant (immediate data). The product, since it has 32 significant bits, goes in dx:ax, meaning the more significant 16 bits go in dx and the less significant in ax. div something16 does the reverse: divides the 32 bits dx:ax by something16 (again, not a constant). But if the quotient exceeds 16 bits, you get a cpu-generated fault. If not, the quotient (rounded down) ends up in ax and the remainder in dx. Pushing ds and 0 to set up an exit is a very old- fashioned manoeuvre, applicable only to DOS. A later retf instruction will give you IP=0 (at the beginning of the Program Segment Prefix) where there is an instruction int 20h meaning exit to DOS. You could simply code int 20h yourself, but in the days of the Ark that could cause trouble. Ever since DOS Version 2, the recommended exit is mov ax,4Cxxh ;xx is ERRORLEVEL int 21h In Win32 (NT especially) you won't be playing with ds very much. To understand mov ax,datastuff mov ds,ax first, mov ds,immed is not possible for the cpu (any masm version). The constant "datastuff" is part of the exe's relocation table; exe-header utilities can sometimes arrange that ds starts with a suitable value and there is no relocation table. Those header utilities can also give you a stack, any size, but if you prefer to use stack segments, be sure to use 'STACK' combine type, or you will get a chunk of zeros in the file unnecessarily. This message was edited by Larry Hammick, on 6/11/2001 3:26:21 PM
Posted on 2001-06-11 15:11:00 by Larry Hammick
I know that that tutorial is old. It's 1989. DO u guys recommend that i ditch it and go for iczelion's tutorial straightaway?
Posted on 2001-06-12 11:57:00 by JCL
Well, not ditch it necessarily. The tute's here at iczelion are good but don't address DOS much. But I would suggest starting with icz's, yes.
Posted on 2001-06-13 04:51:00 by Larry Hammick
Hmm, I've tried to connect to Win32Asm chat but have failed many times, only successful once, where i was disconnected from the server eventually. Any ideas why it happened?
Posted on 2001-06-14 12:37:00 by JCL