Recent Posts

Pages: 1 2 3 [4] 5 6 ... 10
31
Programming with NASM / Re: How are you multiplying by 3
« Last post by gygzkunw on February 22, 2021, 04:34:33 PM »
edx+2 * edx = 3edx-> This is my question, how is this possible?

EDX + 2*EDX = EDX * (1 + 2) = EDX * 3

Elementary arithmetic.

Quote
But earlier mov edx,ecx -> 0 was moved into edx

edx(0)+ 2*edx(0) =should equal to 0, right?
Do you understand what I am saying here?
Yep... this code is obviously WRONG. Or, at least, is incomplete (and ECX is updated in a loop).
I didn't say it wasn't elementary. To get 3 you have to add 1. The question is where does the 1 come from? Up till this point in the author does not explain it.
32
Programming with NASM / Re: How are you multiplying by 3
« Last post by fredericopissarra on February 22, 2021, 03:40:15 PM »
edx+2 * edx = 3edx-> This is my question, how is this possible?

EDX + 2*EDX = EDX * (1 + 2) = EDX * 3

Elementary arithmetic.

Quote
But earlier mov edx,ecx -> 0 was moved into edx

edx(0)+ 2*edx(0) =should equal to 0, right?
Do you understand what I am saying here?
Yep... this code is obviously WRONG. Or, at least, is incomplete (and ECX is updated in a loop).
33
Programming with NASM / Re: How are you multiplying by 3
« Last post by gygzkunw on February 22, 2021, 02:11:02 PM »
edx+2 * edx = 3edx-> This is my question, how is this possible?


But earlier mov edx,ecx -> 0 was moved into edx

edx(0)+ 2*edx(0) =should equal to 0, right?
Do you understand what I am saying here?

34
Programming with NASM / Re: How are you multiplying by 3
« Last post by Frank Kotler on February 22, 2021, 05:21:03 AM »
edx plus two times edx  equals three times edx. I don't think I understand the question.

I have not read Jeff Duntemann's book. I did not mean to give the impression I didn't like it! It has an excellent reputation. I don't have another suggestion. Dr. Paul Carter's Tutorial, perhaps?

Best,
Frank

35
Programming with NASM / Re: How are you multiplying by 3
« Last post by gygzkunw on February 22, 2021, 04:27:45 AM »
Well... it's a "trick" using lea (load effective address) to "load"  edx with edx plus edx times two... As you observe, zero times three is zero. You don't show it, but we then increment edx.. and ,,,

I've never read "Step by Step"... I ASSume Jeff explains this...?

Best,
Frank
I get its a trick but i don't see where the 3 is coming from...

"Not only is this virtually always faster than shifts combined with adds, it’s also clearer from your source code what sort of calculation is actually being done. The fact that what ends up in EDX may not in fact be the legal address of anything is unimportant.LEA does not try to reference the address it calculates.It does the math on the stuff inside the brackets and drops it into the destination operand. Job over. Memory is not touched, and the flags are not affected.Of  course,  you’re  limited  to  what  calculations  can  be  done  on  effective addresses; but right off the top, you can multiply any GP register by 2, 3, 4, 5, 8,and 9, while tossing in a constant too! It’s not arbitrary math, but multiplying by  2,  3,  4,  5,  8,  and  9  comes  up  regularly  in  assembly  work,  and  you  can combine LEA with shifts and adds to do more complex math and ‘‘fill in the holes.’’ You can also use multiple LEA instructions in a row."

Is there a book you like to recommend? You dont seem to like the book...
36
Programming with NASM / Re: How are you multiplying by 3
« Last post by Frank Kotler on February 22, 2021, 03:07:34 AM »
Well... it's a "trick" using lea (load effective address) to "load"  edx with edx plus edx times two... As you observe, zero times three is zero. You don't show it, but we then increment edx.. and ,,,

I've never read "Step by Step"... I ASSume Jeff explains this...?

Best,
Frank




37
Programming with NASM / How are you multiplying by 3
« Last post by gygzkunw on February 22, 2021, 12:21:15 AM »
Code: [Select]
SECTION .bss
BUFFLEN equ 16 ; ----> Bufflen = 16
Buff: resb BUFFLEN ; ----> Buff will read 16 bytes from the buffer

SECTION .data ; Section containing initialised data

HexStr: db " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00",10
HEXLEN equ $-HexStr ; ---->length of Hexstr

Digits: db "0123456789ABCDEF"

SECTION .text ; Section containing code

global _start ; Linker needs this to find the entry point!

_start:
nop ; This no-op keeps gdb happy...

; Read a buffer full of text from stdin:
Read:
mov eax,3 ; ----> syscall read
mov ebx,0 ; ----> read from standard input (keyboard)
mov ecx,Buff ; ----> where the string read is stored
mov edx,BUFFLEN ; ----> how many bytes is supposed to read
int 80h ; ----> sys call
mov ebp,eax ; ----> copy the number that where actually read into ebp
cmp eax,0 ; ----> sub 0 from eax and set the appropriate flag? (if user enters 0 shouldn't the program end?)
je Done ; ----> if the zero flag is set move tone the label done

; Set up the registers for the process buffer step:
mov esi,Buff ; ----> copy the content of Buff into esi
mov edi,HexStr ; ----> copy hexstr into edi
xor ecx,ecx ; ----> Clears ecx

; Go through the buffer and convert binary values to hex digits:
Scan:
s xor eax,eax ; ----> clears eax

; Here we calculate the offset into the line string, which is ecx X 3
mov edx,ecx ; ----> copy ecx which is 0 into edx
lea edx,[edx*2+edx]     ; ----> This is where i am stuck. How are you able to multiply by 3 over here?
LEA = [BASE +( INDEX * SCALE) + DISP)]
      if edx is 0, how are we able to multiply by 3

I am not understand how the author is using the lea instruction
The code is from Assembly Language Step-By-Step by Jeff Duntemann

Thank you
38
Programming with NASM / glPush macro
« Last post by Korybut on February 21, 2021, 02:11:46 PM »
Hello!

As some of you or even all know OperGL requires some parameters to be quad words. Programming for 32 bit system programmers almost always invent some marco operation to deal with this feature (or issue). However the way this macro is realized in NASMX is not very elegant

Code: [Select]
%macro gl_dpush 1
%ifid %1
 push dword [%1+4]
 push dword [%1]
%else
 jmp %%label
  align 4
%%datum:
 dq %1
%%label:
 push dword [%%datum+4]
 push dword [%%datum]
%endif
%endmacro


Is it possible to write a macro that will trasform for example this
Code: [Select]
glpush   1.11111111111111111111
simply into this
Code: [Select]
push   3FF1C71C
push   71C71C72

I've read the preprocessor manual couple of times and some useful examples but unfortuanetly I haven't found the possibility to implement such a macro. Perhaps and I hope  I am missing something
39
Programming with NASM / Re: Flat memory model (Windows)
« Last post by fredericopissarra on February 19, 2021, 03:55:01 PM »
Not advisable. Code must go to `.text` section and data must go to `.data`, `.bss` or  `.rodata` sections.
40
Programming with NASM / Flat memory model (Windows)
« Last post by Korybut on February 19, 2021, 02:20:41 PM »
Hello!

Is possible to write code avoiding section directive and use flat memory model? If yes what object-file format and what linker I should use in this case?
Pages: 1 2 3 [4] 5 6 ... 10