M
M
MikePros2018-05-29 19:32:29
assembler
MikePros, 2018-05-29 19:32:29

"Jump if equal" not working?

I can't figure out why my code is not working properly:

section .data

ok: db "Счетчик аргументов равен 1" , 10, 13, 0
err: db "Счетчик аргументов не равен 1" , 10, 13, 0

section .text
    global _start
_start:

    mov rax, [rsp]
    cmp rax, 2             ;если ARGC == 1
    jne [email protected]
    mov rcx, ok
    mov rax, 1
    mov rdi, 1
    mov rdx, 1

[email protected]:               ;вывести 'Счетчик аргументов равен 1\r\n' в консоль
    cmp [rcx], dword 0
    je [email protected]      ;Эта строка
    mov rsi, rcx
    push rcx
    syscall
    pop rcx
    inc rcx
    jmp [email protected]
[email protected]:

    jmp [email protected]
[email protected]:           ;если ARGC !== 1
    mov rcx, err
    mov rax, 1
    mov rdi, 1
    mov rdx, 1

[email protected]:           ;вывести 'Счетчик аргументов не равен 1\r\n' 
    cmp [rcx], dword 0
    je [email protected]
    mov rsi, rcx
    push rcx
    syscall
    pop rcx
    inc rcx
    jmp [email protected]
[email protected]:

[email protected]:            ;и выйти
    mov rax, 60
    mov rdi, 0
    syscall

When I write in the console ./test, it says "Argument count not equal to 1" (expected behavior).
But if I run ./test abcd, then the console displays
Счетчик аргументов равен 1
Счетчик аргументов не равен 1

When the byte at address RCX is zero and the program reaches the line `je [email protected]`, the JE instruction simply does not jump to the label `[email protected]`.
Why?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
J
jcmvbkbc, 2018-05-29
@MikePros

When the byte at address RCX is zero and the program reaches the line `je [email protected]`, the JE instruction simply does not jump to the label `[email protected]`.
Why?

Because it shouldn't. Because cmp [rcx], dword 0- it's generally a strange record. It would be canonical to write cmp dword ptr [rcx], 0. But in any case, you are not comparing "a byte at the address RCX" with 0, but a whole word. Well, between the lines ok and err there is no whole word of zeros, but after err, obviously, there are.
How to do it right?cmp byte ptr [rcx], 0

V
Viktor Vsk, 2014-08-02
@Jafo

So the question arose of how to do something similar on your own. Not a copy, but the principle itself - concise pages, a minimum of unnecessary information, fast loading, convenient order forms (displaying discount and price parameters while filling out the form), and so on.

To have an excellent sense of taste, to get acquainted with the works of designers and usability specialists outstanding in this regard, to take part in the development of many serious multidirectional projects, in order to understand from your own experience where the pitfalls are.
It's just impossible. Because there are no "sites of a more or less normal look." There is always a subject area and a specific specialization. Design? Photoshop, illustrator, graphic design, web design, desktops, mobile apps, adaptability ? Frontend? Layout, SPA, specific mobile platform? Backend? Banking apps or social networks?
In your case, it seems to me that the most useful thing is to take your site from the example as a sample (since I liked it so much) and try to make a copy of it in pure HTML in a month or two (using it for convenience, development speed and to keep up with the times and get real favor), things like static site generators, version control system, bug trackers and preprocessors (for html - haml\slim\jade... , for css: LESS\SAS, for JS, I think it's not worth it to start with. If at all it’s cool to hit the layout (frontend), then also use the CSS methodology (smacss, bem ...)), as well as do all this in a normal OS (unix-like), and not in a notepad, but in an IDE.
Thus, in a few months, you can become well acquainted with the modern technology stack. Without going too much into server-side languages, I think there will be a general understanding of how the web works in general. Plus, you should get good knowledge of layout, which will come in handy anyway, even if you come close to server languages, because. html\css has to be written by everyone sometimes.
When your site is an exact copy (or improved) of your example and it will be possible to follow the links using the built-in server of the static site generator (without server logic), it may become interesting to fasten the front-end MV * framework and emulate the back-end (what would be possible like order something, add to cart, leave a review), then go to the next step.
Next, understand what your site is like in the example: try to describe it in the terms of reference - what modules it uses (guest, shop, chat, forum ...), what are the requirements for each of them. Approximately estimate the load (number of users, clicks, views, interaction with logic... These are all very useful skills if you are really going to do something like this, because not everyone now has a common vision of the final system, although modern tools provide such an opportunity.After
the technical task is ready, already decide what is better, take a CMS and finish it or use a framework.Also, decide on a technology stack (do not make a business card site on erlang and mongodb, but cms \ in ruby).

I
Igor It doesn't matter, 2014-08-02
@HellFir-e

in principle, this can be written with basic knowledge of html + css + php + js (and all this at the level of copy-paste + learning the basics), i.e. to study + write.
What is there is literally the basics that you will find in books for beginners or on sites (except for js, but here you can use ready-made libraries and scripts). if you need to be directed or described in more detail, write in the comments to this answer, I will give contacts for communication

A
Alexander Reshetnyak, 2016-07-09
@Vampireos

after you learn html css js, it's time to take a look at https://webasyst.ru

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question