loops - Code executes condition wrong? -


basic question here,

i wrote following block:

    ideal     model small     stack 100h     dataseg      var1 db 4     var2 db 2      codeseg  start:     mov ax, @data     mov ds, ax     xor ax, ax     mov al, [var1]     cmp al, [var2]     jg  var1greater     mov ax, 1 var1greater:     mov ax, 0 

i'm new assembly.

i wanted create code compares [var1] [var2].

if(!) [var1] greater [var2], execute mov ax, 1. if(1) else(equal or less) excecute, mov ax, 0.

how can done? code wrote executes both instructions if condition true.

ah, turbo assembler "ideal" mode; has been while since last saw it. love ideal mode. better thought-out , makes more sense microsoft assembler's syntax.

well, happening both instructions executed.

first, mov ax, 0 gets executed, , control falls through next statement, mov ax, 1, left in ax 1.

labels in assembly language not magically cause control jump elsewhere. not cause assembler emit instructions. exist can indicate target of jump instruction.

so, need is:

    ...     cmp al, [var2]     jg  var1greater     mov ax, 0     jmp skip var1greater:     mov ax, 1 skip: 

also, form when writing assembly language use xor ax, ax instead of mov ax, 0.


Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -