Recent Posts

Pages: 1 ... 8 9 [10]
91
Programming with NASM / Re: Palindrome
« Last post by fredericopissarra on April 25, 2019, 08:53:06 PM »
Change:
Code: [Select]
cmp [eax], [ecx]To:
Code: [Select]
mov dl,[ecx]
cmp [eax],dl
92
Programming with NASM / Own charset in C or assembler and keyboard input
« Last post by lukassevc on April 25, 2019, 07:34:56 PM »
Hi, I am Lucas and i have one question. I am no from English speaking country ( I am from Slovakia ( not from Slovenia ) ) and I am making my own OS in C and assembler but when I came to printing text on screen and I want to use my characters ( that I use in my country ) I don't know how to use them because C compiler doesn't compiled it very well for my OS so it didn't work. Later i change text encoding ( to ISO 8859-2 ) it worked better but not enough - some characters it did compiled correctly and some not, and I don't know know how to fix it, I decide best way will be make own charset but I don't know how to do it. Also I need help with keyboard in C - i know that I can read input from it using port 0x60 and 0x64 but i need also recognize characters and here is my problem - 
using scan odes i don't know if some key on keyboard has special scan code or if special letter has own and unique scan code if first it will be easy to make function to read for example Slovak, English, American or any keyboard because special key has own scan code and doesn't depends on letters written on it but if second it will be harder because i can'f find Slovak keyboard scan codes so please help me, it is confusing me ( very very confusing )  - sorry for mistakes, because ( as I mentioned before  ) I am not from English speaking country.

Thanks for help and understand.
93
Programming with NASM / Palindrome
« Last post by Shark44 on April 25, 2019, 03:59:48 PM »
Hello, I want to verify if a word is palindrome but I can't compare 2 memories. Can someone tell me a way to fix this?
Code: [Select]
SECTION .text
global  _start

_start: ; tell linker entry point.
    mov ecx, string
    add ecx, len
    sub ecx, 3
    mov eax, string
    mov ebx, len
    _ciclo:
    push eax
    push ecx 
    cmp [eax], [ecx]
    jnz _stampaNonPalindroma
    pop ecx
    pop eax
    inc eax
    dec ecx
    dec ebx
    cmp ebx,0h
    jnz _ciclo
    jmp _stampaPalindroma ;se uscir√† "indenne" dal ciclo vuol dire che la parola √® palindroma
_stampaPalindroma:
    mov ecx, string2
    mov edx, len2
    mov ebx, 1  ; file descriptor (stdout)
    mov eax, 4  ; system call number (sys_write)
    int 0x80
    jmp _esci

_stampaNonPalindroma:
    mov ecx, string3
    mov edx, len3
    mov ebx, 1
    mov eax, 4
    int 0x80
    jmp _esci

_esci:
    mov     eax, 1
    int     0x80

section .data
string: db "anna",10,13 ;10 line feed, 13 carriage return, 0 null.
len:    equ $-string
string2: db "Palindroma",10,13
len2:   equ $-string2
string3: db "Non Palindroma",10,13
len3:   equ $-string3
94
From NASM doc:

Quote
The function of the AT macro is to make use of the TIMES prefix to advance the assembly position to the correct point for the specified structure field, and then to declare the specified data. Therefore the structure fields must be declared in the same order as they were specified in the structure definition.

And, so, this works:

Code: [Select]
bits 64
default rel

section .data

struc mystruc
.value: resd  1
.next:  resq  1
.prev:  resq  1
endstruc

p:  dq  0

mylist:
  istruc mystruc
    at mystruc.value, dd 1
    at mystruc.next,  dq p
    at mystruc.prev,  dq p
  iend
95
This is part of my code:

SECTION .data
   Head: ISTRUC Node
      AT Node.Value, dd 0
      AT Node.NextPtr, dd Second
      AT Node.PrevPtr, dd Tail
   IEND

   Second: ISTRUC Node
      AT Node.Value, dd 0
      AT Node.NextPtr, dd Tail
      AT Node.PrevPtr, dd Head
   IEND
   
   Tail: ISTRUC Node
      AT Node.Value, dd 0
      AT Node.NextPtr, dd Head
      AT Node.PrevPtr, dd Second
   IEND

I am getting the error "non-constant argument supplied to TIMES" for each line that uses "IEND".
Any help would be greatly appreciated.
96
Programming with NASM / Re: [Solved] Segmentation fault in a snippet for C++
« Last post by Xotes on April 23, 2019, 04:48:16 PM »
I kinda understand where you are going :O But unfortunately I think I might get spotted if I use these kind of lines, we've never even seen it in class :) Right now it works and I must say I'm not really asking for more :)
97
Programming with NASM / Re: Segmentation fault in a snippet for C++
« Last post by fredericopissarra on April 23, 2019, 01:20:39 AM »
Sorry, I've had a busy week-end -_-

I have to implement it via an object file using "nasm -f elf32 -g" and use it as an extern function in c++.
32 bit, using gcc on ubuntu (18.10 to be precise).

Then you must use SysV ABI calling convention for i386 processors. First, the function arguments must be passed through the stack. Second, registers as EBX, EDI, ESI and EBP must be preverved between calls. You can change, freely, EAX, ECX and EDX. So, if you will use ESI and EDI as base registers (for LODSD/STOSD instructions), they must be saved. Here's a simple solution:

Code: [Select]
  bits  32

  section .text

; f function stack frame.
struc fstk
.oldesi:  resd  1   ; We won't use this, but
.oldedi:  resd  1   ; ESP will be changed after saving
                    ; EDI and ESI in the stack.

.retaddr: resd  1   ; CALL f will put this on stack.

.destptr: resd  1   ; cdecl call will push arguments
.srcptr:  resd  1   ; from last to first.
.count:   resd  1
endstruc

; void f( int *destptr, int *srcptr, unsigned int count );
  global  f
f:
  ; Save EDI and ESI (SysV ABI i386 calling convention).
  push  edi
  push  esi

  ; Get arguments from stack.
  mov   edi,[esp+fstk.destptr]
  mov   esi,[esp+fstk.srcptr]
  mov   ecx,[esp+fstk.count]

  jmp   .test_cond

.loop:
  lodsb           ; Load EAX from DS:ESI
  add   eax,eax   ; EAX = EAX * 2
  stosb           ; Store EAX to ES:EDI

.test_cond:
  sub   ecx,1
  jnc   .loop     ; Stay on loop if ECX >= 0

  ; Restore EDI and ESI.
  pop   esi
  pop   edi
  ret

Quote from: Xotes
I might have found the problem -_- I read somewhere in the seldom documentation we where given that the first argument was at +8... Now, when I put +4 I at least get to the end of my code. But another problem arose, which I'm trying to figure out now.
To avoid the problem to calculate the offsets on the stack, use the structural stack frame tip I showed you above...
98
Programming with NASM / Re: [Solved] Segmentation fault in a snippet for C++
« Last post by Xotes on April 23, 2019, 01:15:38 AM »
So thank you for your quick reply, even though I was slow to see it :)
99
Programming with NASM / Re: Segmentation fault in a snippet for C++
« Last post by Xotes on April 23, 2019, 12:34:53 AM »
Sorry, I've had a busy week-end -_-

I have to implement it via an object file using "nasm -f elf32 -g" and use it as an extern function in c++.
32 bit, using gcc on ubuntu (18.10 to be precise).

I've tried fidgeting with ecx but it does not seem to have an effect.

EDIT : I had changed something else, rendering my code completely useless -_- Assembly is kinda driving me crazy
EDIT' : I'm just dumb -_- I put my parameters in the wrong order comparing to the function, so it would have had a hard time working. Now it works, just fine
100
Programming with NASM / Re: Segmentation fault in a snippet for C++
« Last post by dreamCoder on April 21, 2019, 08:21:34 PM »
Ok thanks for the tips.

I was actually commenting on the possibility that the OP was dual-using ECX. One as the default loop count (in LOOPNZ) and the other one was for maintaining "length of vector" value? Wasn't very clear to me until I read it the second time.
Pages: 1 ... 8 9 [10]