Recent Posts

Pages: 1 [2] 3 4 ... 10
11
Website and Forum / Re: nasm.us certificate expired this morning
« Last post by netjunki on February 24, 2021, 12:59:00 AM »
Seems to be fixed now! Thanks to whoever (or the bot) which cycled the cert. :-)
12
Website and Forum / nasm.us certificate expired this morning
« Last post by netjunki on February 23, 2021, 07:16:17 PM »
Hey all,

It looks like the nasm.us https certificate expired this morning. Looking at the details maybe the script which is run to regenerate it through Let's Encrypt failed to run.

Cheers,
Ben
13
Programming with NASM / Re: How are you multiplying by 3
« Last post by debs3759 on February 22, 2021, 07:04:20 PM »
I can't figure out what you are not seeing? (EDX * 2) + EDX is obviously 3 * EDX, where are you seeing the "1" that you don't understand?

0 can be multiplied by any number...
14
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.
15
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).
16
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?

17
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

18
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...
19
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




20
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
Pages: 1 [2] 3 4 ... 10