Recent Posts

Pages: [1] 2 3 ... 10
1
Example Code / Re: BASELIB: General Purpose Lib for Beginners
« Last post by stressful on Today at 03:59:33 AM »
Ok now once you have included "prnint128 and prnint128u" in your base64w / base64x sources, you can for example use them to extend calculations beyond 64-bit limitation.

Using ADCX:
Code: [Select]
main:
        sub     rsp,40
        mov     rax,-1  ;maxed-out RAX
        mov     rbx,2   ;add 2
        adcx    rax,rbx
        jc      .carry
        push    0
        push    rax
        mov     rax,rsp
        call    prnint128u
        add     rsp,56
        ret
.carry:
        push    1
        push    rax
        mov     rax,rsp
        call    prnint128u
        add     rsp,56
        ret

Result should be: 18446744073709551617 instead of 1 as in normal saturated arithmetic in 64-bit world.

Now using MULX:
Code: [Select]
        section .text
main:
        sub     rsp,40
        mov     rcx,-1  ;maxed-out RCX
        mov     rdx,2   ;mul 2
        mulx    rax,rbx,rcx
        push    rax
        push    rbx
        mov     rax,rsp
        call    prnint128u
        add     rsp,56
        ret

Result should be: 36893488147419103230 (as in 18446744073709551615 x 2).

Just to remind you that these are unofficial extensions and not part of core BASELIB. Maybe someday I'd consider adding BigInt routines in there.

Good luck and enjoy your weekend.

 
2
Programming with NASM / Re: How to rename reserved words in the NASM?
« Last post by sal55 on September 22, 2018, 08:32:37 PM »
Ummm, no?

Seriously, and without meaning any insult, I question if you don't want "mov" to exist, whether Nasm is what you're looking for.
A year ago I wanted something similar. I don't know about the OP's reasons (and this is an old thread) but when you machine-generate ASM code from another language, then it happens that some identifiers used in the original language can clash with reserved words in Nasm.

Sometimes you can 'decorate' such names to avoid a clash, but sometimes also the names have to be just as they are in order to link with those names exported from elsewhere. (One I had problems with as 'abs' IIRC.)

Quote
If you got into the sourcecode - x86/insns.dat - and made changes there - you might be able to create a tool that does what you want... instead of what Nasm does...

That won't help unless you rename all opcodes and register names to have unlikely prefixes or suffixes, otherwise there is still a risk of a clash. And then the same assembler build won't work for conventional code.

Some assemblers are aware of such problems and will provide workarounds (I'm using such an alternative now). But I'm just pointing out the OP's requirement isn't that crazy.
3
Example Code / Re: BASELIB: General Purpose Lib for Beginners
« Last post by stressful on September 22, 2018, 11:33:28 AM »
For unsigned Hex, both 512-bit and 256-bit...
I don't know if this works because I have no calculators big enough for verification purposes.. ;D

Code: [Select]
;-------------------------------
;prnhex512u(1)
;Display Unsigned 512-bit Hex
;-------------------------------
;RAX    : Address of a 512-bit to display
;-------------------------------
;Ret    : -
;Note   : Eight consecutive QWORDS in memory
;         that sum up to the 512-bit value
;-------------------------------
align 8
prnhex512u:
        push    rax
        push    rbx
        push    rcx
        push    rdx
        push    rsi
        push    rdi
        sub     rsp,128
        mov     rsi,rax
        mov     rbx,[rsi+56]
        mov     rdi,rsp
        cld
        mov     ecx,16
.msb:   xor     eax,eax
        shld    rax,rbx,4
        add     al,30h
        cmp     al,'0'
        jz      .nope
        cmp     al,'9'
        jbe     .ok
        add     al,7
.ok:    stosb
.nope:  shl     rbx,4
        sub     ecx,1
        jnz     .msb
;-------------------------
        mov     edx,7
.more:  sub     rsi,8
        mov     ecx,16
        mov     rbx,[rsi+56]
.next:  xor     eax,eax
        shld    rax,rbx,4
        add     al,30h
        cmp     al,'9'
        jbe     .ok1
        add     al,7
.ok1:   stosb
.nope1: shl     rbx,4
        sub     ecx,1
        jnz     .next
        sub     edx,1
        jnz     .more
        xor     al,al
        stosb
        mov     rax,rsp
        sub     rsp,32
        call    prnstrz
        add     rsp,160
        pop     rdi
        pop     rsi
        pop     rdx
        pop     rcx
        pop     rbx
        pop     rax
        ret
;-------------------------------
;prnhex256u(1)
;Display unsigned 256-bit Hex
;-------------------------------
;RAX    : Address of a 256-bit to display
;-------------------------------
;Ret    : -
;Note   : Four consecutive QWORDS in memory
;         that sum up to the 256-bit value
;-------------------------------
align 8
prnhex256u:
        push    rax
        push    rbx
        push    rcx
        push    rdx
        push    rsi
        push    rdi
        sub     rsp,72
        mov     rsi,rax
        mov     rbx,[rsi+24]
        mov     rdi,rsp
        cld
        mov     ecx,16
.msb:   xor     eax,eax
        shld    rax,rbx,4
        add     al,30h
        cmp     al,'0'
        jz      .nope
        cmp     al,'9'
        jbe     .ok
        add     al,7
.ok:    stosb
.nope:  shl     rbx,4
        sub     ecx,1
        jnz     .msb
;-------------------------
        mov     edx,3
.more:  sub     rsi,8
        mov     ecx,16
        mov     rbx,[rsi+24]
.next:  xor     eax,eax
        shld    rax,rbx,4
        add     al,30h
        cmp     al,'9'
        jbe     .ok1
        add     al,7
.ok1:   stosb
.nope1: shl     rbx,4
        sub     ecx,1
        jnz     .next
        sub     edx,1
        jnz     .more
        xor     al,al
        stosb
        mov     rax,rsp
        sub     rsp,32
        call    prnstrz
        add     rsp,104
        pop     rdi
        pop     rsi
        pop     rdx
        pop     rcx
        pop     rbx
        pop     rax
        ret

If it works, it works. If don't, don't bother. For example;
Code: [Select]
        ;default rel
        global main

        section .data align=32
msg:    db 'Hello World',0ah,0
y:      dq -1,-1,-1,0ABCDEFh,-1,-1,-1,0x7fffffffffffffff

        section .text
main:
        sub     rsp,40

        mov     rax,y
        call    prnhex512u

        add     rsp,40
        ret

Output

Code: [Select]
7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0000000000ABCDEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
4
Example Code / Re: BASELIB: General Purpose Lib for Beginners
« Last post by stressful on September 22, 2018, 11:14:17 AM »
I've been getting requests to come up with BigInt/Num routines for this library in NASM. But I have no intention to provide such support in the current distribution. My personal opinion is that 64-bit numbers are big enough for most beginners' purposes. 128-bit seems to be out of this world. So, my apologies, there will be no such support provided by BASELIB. But for those who really (like really really) need 128-bit integers, I can give you two makeshift routines that deal with such conversion.

Code: [Select]
;-------------------------------
;prnint128(1)
;Display signed 128-bit integer
;-------------------------------
;RAX    : Address of a 128-bit to display
;-------------------------------
;Ret    : -
;Note   : Two consecutive QWORDS in memory
;         that sum up to the 128-bit value
;-------------------------------
align 8
prnint128:
        push    rax
        push    rbx
        push    rcx
        push    rdx
        push    rsi
        push    rdi
        push    r8
        sub     rsp,64
        mov     ecx,10
        xor     r8d,r8d
        mov     rbx,[rax+8]
        mov     rsi,[rax]
        bt      rbx,63
        jnc     .plus
        cmp     rsi,0
        jne     .mm
        neg     rbx
        jmp     .nn
.mm:    not     rbx
.nn:    not     rsi
        mov     r8d,1
        add     rsi,1
.plus:  mov     rdi,rsp
        add     rdi,63
        mov     byte[rdi],0
.again: xor     edx,edx
        mov     rax,rbx
        div     rcx
        mov     rbx,rax
        mov     rax,rsi
        div     rcx
        mov     rsi,rax
        add     dl,30h
        sub     rdi,1
        mov     byte[rdi],dl
        mov     rax,rbx
        or      rax,rsi
        jnz     .again
        test    r8,r8
        jz      .done
        sub     rdi,1
        mov     byte[rdi],'-'
.done:  mov     rax,rdi
        sub     rsp,32
        call    prnstrz
        add     rsp,96
        pop     r8
        pop     rdi
        pop     rsi
        pop     rdx
        pop     rcx
        pop     rbx
        pop     rax
        ret
;-------------------------------
;prnint128u(1)
;Display Unsigned 128-bit int
;-------------------------------
;RAX    : Address of a 128-bit to display
;-------------------------------
;Ret    : -
;Note   : Two consecutive QWORDS in memory
;         that sum up to the 128-bit value
;-------------------------------
align 8
prnint128u:
        push    rax
        push    rbx
        push    rcx
        push    rdx
        push    rsi
        push    rdi
        sub     rsp,72
        mov     ecx,10
        mov     rbx,[rax+8]
        mov     rsi,[rax]
        mov     rdi,rsp
        add     rdi,63
        mov     byte[rdi],0
.again: xor     edx,edx
        mov     rax,rbx
        div     rcx
        mov     rbx,rax
        mov     rax,rsi
        div     rcx
        mov     rsi,rax
        add     dl,30h
        sub     rdi,1
        mov     byte[rdi],dl
        mov     rax,rbx
        or      rax,rsi
        jnz     .again
        mov     rax,rdi
        sub     rsp,32
        call    prnstrz
        add     rsp,104
        pop     rdi
        pop     rsi
        pop     rdx
        pop     rcx
        pop     rbx
        pop     rax
        ret

You can add these two in "base64w/base64x" sources and try to play around with it. Like for example;

Code: [Select]
        ;default rel
        global main

        section .data align=32
msg:    db 'Hello World',0ah,0
y:      dq -1,-1

        section .text
main:
        sub     rsp,40

        mov     rax,y
        call    prnint128
        call    prnline
        mov     rax,y
        call    prnint128u

        add     rsp,40
        ret

You can try using instructions like ADCX and MULX to test the accuracy of the functions above (for example, adding two 64-bit registers, without carry).

Good luck.
 
EDIT: Replace the divisor with 8 for octal, and 16 for hex. Now u can get 4 more extra routines for signed and unsigned hex and octal.
5
Programming with NASM / Re: nasm + lld-link
« Last post by fredericopissarra on September 18, 2018, 06:20:42 PM »
There is no "import" directive in NASM... All symbols resolution is made in linking phase...
6
Other Discussion / Re: CPU emulator
« Last post by shaynox on September 18, 2018, 07:55:57 AM »
Maybe, but the problem of machine emulator is that they have more than 1 incompatibility with my OS, I forgot how much, there is the LFB address as example that is different, but when using it with real machine, the problem disappear.
7
Other Discussion / Re: CPU emulator
« Last post by jeniferconnorsmk on September 18, 2018, 07:36:09 AM »
One important thing should be noted here is that running an application with different options or input will also trigger different behavior and dynamic execution, so one cannot assume that a single run of an application will tell them the whole story

Regards

my assignment help reviews
myassignmenthelp reviews
8
Using NASM / Re: why i see the text like this
« Last post by yoran on September 15, 2018, 08:11:02 AM »
It's probably a name, saved as a raw string.
9
Using NASM / why i see the text like this
« Last post by fsurta on September 14, 2018, 05:13:24 PM »
https://imgur.com/a/iUtnYnW please check the image and help me
10
Programming with NASM / nasm + lld-link
« Last post by NASM on September 12, 2018, 11:20:36 AM »
Help me pls import function


Code: [Select]
BITS 64

SECTION .bss

  hSocket:  resq 1

SECTION .data

port: equ 777

struc WSADATA
  .wVersion:  resw 1
  .wHighVersion:  resw 1
  .szDescription:  resb 256
  .szSystemStatus:  resb 256
  .iMaxSockets:  resd 1
  .iMaxUdpDg:  resd 1
  .lpVendorInfo:  resq 1
endstruc

struc sockaddr_in
  .sin_family:  resd 1
  .sin_port:  resd 1
  .sin_addr:  resq 1
  .sin_zero:  resb 8
  .size:
endstruc

SECTION .text

global start

extern WSAStartup
extern WSACleanup
extern socket
extern Sleep

extern ExitProcess
import ExitProcess kernel32.dll

extern accept
extern listen
extern bind

start:

  mov rdx , [WSADATA]
  mov rcx , 0x202
  call WSAStartup
 
  mov r8 , 0
  mov rdx , 1
  mov rcx , 2
  call socket
 
  mov [hSocket] , rax
  mov dword [sockaddr_in.sin_family] , 1
  mov qword [sockaddr_in.sin_addr] , 0
  mov ax , port
  xchg ah , al
  mov [sockaddr_in.sin_port] , ax
  mov r8 , sockaddr_in.size
  mov rdx , [sockaddr_in]
  mov rcx , hSocket
  call bind
 
  mov rdx , 13
  mov rcx , hSocket
  call listen
 
  mov r8 , 0
  mov rdx , [sockaddr_in]
  mov rcx , hSocket
  call accept
 
  mov rcx , 60000
  call Sleep
 
  call WSACleanup
 
  mov rcx,0
  call ExitProcess

C:\msys64\home\Alexey>nasm cmd.asm -f win64 -o cmd.obj
cmd.asm:39: error: parser: instruction expected


https://wasm.in/threads/lld-bsd-exe.32375/#post-402921
Pages: [1] 2 3 ... 10