Understanding conditional jumps












0















[org 100h]

jmp start

start:
MOV AL, 5
MOV BL, 0xFF
CMP AL, BL
JG L1
MOV AX, 0
JMP Exit
L1:
MOV AX, 1
Exit:

mov ax,0x4c00
int 21h


Why does this jump to L1 after JG? As here al < bl and it should only jump to L1 if al > bl.



Am I right though?



The end result in ax should be 0 but it is giving 1. I'm using dosbox 0.74 and I'm a beginner in assembly.










share|improve this question




















  • 1





    5 > -1, so al is greater. Why do you think it's less/equal? ( felixcloutier.com/x86/Jcc.html .. the cmp instruction will set flags in a way that mnemonics like jg = jump if greater and ja = jump if above work as expected ... (when you understand the basic data types and why 8 bit -1 is encoded as 1111_1111 in binary, i.e. 0xFF) ... for SIGNED integers in 8 bits you have working range -128..+127 .. for unsigned integers the range is 0..255 (you are loading bl with bit pattern "1111_1111" which can be interpreted as 255 (unint8) or -1 (int8) or anything (anything_t).

    – Ped7g
    Nov 20 '18 at 16:48








  • 1





    is it not 5 > 255 :@ what is wrong with me... how can i make bl 255? changing jg to ja does that?

    – 5D_cOOKIE
    Nov 20 '18 at 16:50













  • 0xff is -1 in 8-bit 2's complement.

    – Peter Cordes
    Nov 20 '18 at 16:50






  • 1





    2) in that shortened Intel manual (link), the unsigned-related jumps are ja/jb/... ("below/above"), signed-related jumps are jg/jl/... ("greater/less"). But keep in mind they actually don't care about their name, they just check current flag status, set up by whatever last instruction(s)... Also don't assume much about flags being set by instructions, most of the time the arithmetic instructions set them as expected, but there are exceptions, like dec/inc does NOT modify CF (for good reasons, but it may surprise you) - so check inst. guide.

    – Ped7g
    Nov 20 '18 at 17:03








  • 2





    Please read Under what circumstances may I add “urgent” or other similar phrases to my question, in order to obtain faster answers? - the summary is that this is not an ideal way to address volunteers, and is probably counterproductive to obtaining answers. Please refrain from adding this to your questions.

    – halfer
    Nov 20 '18 at 17:55
















0















[org 100h]

jmp start

start:
MOV AL, 5
MOV BL, 0xFF
CMP AL, BL
JG L1
MOV AX, 0
JMP Exit
L1:
MOV AX, 1
Exit:

mov ax,0x4c00
int 21h


Why does this jump to L1 after JG? As here al < bl and it should only jump to L1 if al > bl.



Am I right though?



The end result in ax should be 0 but it is giving 1. I'm using dosbox 0.74 and I'm a beginner in assembly.










share|improve this question




















  • 1





    5 > -1, so al is greater. Why do you think it's less/equal? ( felixcloutier.com/x86/Jcc.html .. the cmp instruction will set flags in a way that mnemonics like jg = jump if greater and ja = jump if above work as expected ... (when you understand the basic data types and why 8 bit -1 is encoded as 1111_1111 in binary, i.e. 0xFF) ... for SIGNED integers in 8 bits you have working range -128..+127 .. for unsigned integers the range is 0..255 (you are loading bl with bit pattern "1111_1111" which can be interpreted as 255 (unint8) or -1 (int8) or anything (anything_t).

    – Ped7g
    Nov 20 '18 at 16:48








  • 1





    is it not 5 > 255 :@ what is wrong with me... how can i make bl 255? changing jg to ja does that?

    – 5D_cOOKIE
    Nov 20 '18 at 16:50













  • 0xff is -1 in 8-bit 2's complement.

    – Peter Cordes
    Nov 20 '18 at 16:50






  • 1





    2) in that shortened Intel manual (link), the unsigned-related jumps are ja/jb/... ("below/above"), signed-related jumps are jg/jl/... ("greater/less"). But keep in mind they actually don't care about their name, they just check current flag status, set up by whatever last instruction(s)... Also don't assume much about flags being set by instructions, most of the time the arithmetic instructions set them as expected, but there are exceptions, like dec/inc does NOT modify CF (for good reasons, but it may surprise you) - so check inst. guide.

    – Ped7g
    Nov 20 '18 at 17:03








  • 2





    Please read Under what circumstances may I add “urgent” or other similar phrases to my question, in order to obtain faster answers? - the summary is that this is not an ideal way to address volunteers, and is probably counterproductive to obtaining answers. Please refrain from adding this to your questions.

    – halfer
    Nov 20 '18 at 17:55














0












0








0








[org 100h]

jmp start

start:
MOV AL, 5
MOV BL, 0xFF
CMP AL, BL
JG L1
MOV AX, 0
JMP Exit
L1:
MOV AX, 1
Exit:

mov ax,0x4c00
int 21h


Why does this jump to L1 after JG? As here al < bl and it should only jump to L1 if al > bl.



Am I right though?



The end result in ax should be 0 but it is giving 1. I'm using dosbox 0.74 and I'm a beginner in assembly.










share|improve this question
















[org 100h]

jmp start

start:
MOV AL, 5
MOV BL, 0xFF
CMP AL, BL
JG L1
MOV AX, 0
JMP Exit
L1:
MOV AX, 1
Exit:

mov ax,0x4c00
int 21h


Why does this jump to L1 after JG? As here al < bl and it should only jump to L1 if al > bl.



Am I right though?



The end result in ax should be 0 but it is giving 1. I'm using dosbox 0.74 and I'm a beginner in assembly.







assembly x86






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 '18 at 18:03









Peter Cordes

129k18194329




129k18194329










asked Nov 20 '18 at 16:47









5D_cOOKIE5D_cOOKIE

12




12








  • 1





    5 > -1, so al is greater. Why do you think it's less/equal? ( felixcloutier.com/x86/Jcc.html .. the cmp instruction will set flags in a way that mnemonics like jg = jump if greater and ja = jump if above work as expected ... (when you understand the basic data types and why 8 bit -1 is encoded as 1111_1111 in binary, i.e. 0xFF) ... for SIGNED integers in 8 bits you have working range -128..+127 .. for unsigned integers the range is 0..255 (you are loading bl with bit pattern "1111_1111" which can be interpreted as 255 (unint8) or -1 (int8) or anything (anything_t).

    – Ped7g
    Nov 20 '18 at 16:48








  • 1





    is it not 5 > 255 :@ what is wrong with me... how can i make bl 255? changing jg to ja does that?

    – 5D_cOOKIE
    Nov 20 '18 at 16:50













  • 0xff is -1 in 8-bit 2's complement.

    – Peter Cordes
    Nov 20 '18 at 16:50






  • 1





    2) in that shortened Intel manual (link), the unsigned-related jumps are ja/jb/... ("below/above"), signed-related jumps are jg/jl/... ("greater/less"). But keep in mind they actually don't care about their name, they just check current flag status, set up by whatever last instruction(s)... Also don't assume much about flags being set by instructions, most of the time the arithmetic instructions set them as expected, but there are exceptions, like dec/inc does NOT modify CF (for good reasons, but it may surprise you) - so check inst. guide.

    – Ped7g
    Nov 20 '18 at 17:03








  • 2





    Please read Under what circumstances may I add “urgent” or other similar phrases to my question, in order to obtain faster answers? - the summary is that this is not an ideal way to address volunteers, and is probably counterproductive to obtaining answers. Please refrain from adding this to your questions.

    – halfer
    Nov 20 '18 at 17:55














  • 1





    5 > -1, so al is greater. Why do you think it's less/equal? ( felixcloutier.com/x86/Jcc.html .. the cmp instruction will set flags in a way that mnemonics like jg = jump if greater and ja = jump if above work as expected ... (when you understand the basic data types and why 8 bit -1 is encoded as 1111_1111 in binary, i.e. 0xFF) ... for SIGNED integers in 8 bits you have working range -128..+127 .. for unsigned integers the range is 0..255 (you are loading bl with bit pattern "1111_1111" which can be interpreted as 255 (unint8) or -1 (int8) or anything (anything_t).

    – Ped7g
    Nov 20 '18 at 16:48








  • 1





    is it not 5 > 255 :@ what is wrong with me... how can i make bl 255? changing jg to ja does that?

    – 5D_cOOKIE
    Nov 20 '18 at 16:50













  • 0xff is -1 in 8-bit 2's complement.

    – Peter Cordes
    Nov 20 '18 at 16:50






  • 1





    2) in that shortened Intel manual (link), the unsigned-related jumps are ja/jb/... ("below/above"), signed-related jumps are jg/jl/... ("greater/less"). But keep in mind they actually don't care about their name, they just check current flag status, set up by whatever last instruction(s)... Also don't assume much about flags being set by instructions, most of the time the arithmetic instructions set them as expected, but there are exceptions, like dec/inc does NOT modify CF (for good reasons, but it may surprise you) - so check inst. guide.

    – Ped7g
    Nov 20 '18 at 17:03








  • 2





    Please read Under what circumstances may I add “urgent” or other similar phrases to my question, in order to obtain faster answers? - the summary is that this is not an ideal way to address volunteers, and is probably counterproductive to obtaining answers. Please refrain from adding this to your questions.

    – halfer
    Nov 20 '18 at 17:55








1




1





5 > -1, so al is greater. Why do you think it's less/equal? ( felixcloutier.com/x86/Jcc.html .. the cmp instruction will set flags in a way that mnemonics like jg = jump if greater and ja = jump if above work as expected ... (when you understand the basic data types and why 8 bit -1 is encoded as 1111_1111 in binary, i.e. 0xFF) ... for SIGNED integers in 8 bits you have working range -128..+127 .. for unsigned integers the range is 0..255 (you are loading bl with bit pattern "1111_1111" which can be interpreted as 255 (unint8) or -1 (int8) or anything (anything_t).

– Ped7g
Nov 20 '18 at 16:48







5 > -1, so al is greater. Why do you think it's less/equal? ( felixcloutier.com/x86/Jcc.html .. the cmp instruction will set flags in a way that mnemonics like jg = jump if greater and ja = jump if above work as expected ... (when you understand the basic data types and why 8 bit -1 is encoded as 1111_1111 in binary, i.e. 0xFF) ... for SIGNED integers in 8 bits you have working range -128..+127 .. for unsigned integers the range is 0..255 (you are loading bl with bit pattern "1111_1111" which can be interpreted as 255 (unint8) or -1 (int8) or anything (anything_t).

– Ped7g
Nov 20 '18 at 16:48






1




1





is it not 5 > 255 :@ what is wrong with me... how can i make bl 255? changing jg to ja does that?

– 5D_cOOKIE
Nov 20 '18 at 16:50







is it not 5 > 255 :@ what is wrong with me... how can i make bl 255? changing jg to ja does that?

– 5D_cOOKIE
Nov 20 '18 at 16:50















0xff is -1 in 8-bit 2's complement.

– Peter Cordes
Nov 20 '18 at 16:50





0xff is -1 in 8-bit 2's complement.

– Peter Cordes
Nov 20 '18 at 16:50




1




1





2) in that shortened Intel manual (link), the unsigned-related jumps are ja/jb/... ("below/above"), signed-related jumps are jg/jl/... ("greater/less"). But keep in mind they actually don't care about their name, they just check current flag status, set up by whatever last instruction(s)... Also don't assume much about flags being set by instructions, most of the time the arithmetic instructions set them as expected, but there are exceptions, like dec/inc does NOT modify CF (for good reasons, but it may surprise you) - so check inst. guide.

– Ped7g
Nov 20 '18 at 17:03







2) in that shortened Intel manual (link), the unsigned-related jumps are ja/jb/... ("below/above"), signed-related jumps are jg/jl/... ("greater/less"). But keep in mind they actually don't care about their name, they just check current flag status, set up by whatever last instruction(s)... Also don't assume much about flags being set by instructions, most of the time the arithmetic instructions set them as expected, but there are exceptions, like dec/inc does NOT modify CF (for good reasons, but it may surprise you) - so check inst. guide.

– Ped7g
Nov 20 '18 at 17:03






2




2





Please read Under what circumstances may I add “urgent” or other similar phrases to my question, in order to obtain faster answers? - the summary is that this is not an ideal way to address volunteers, and is probably counterproductive to obtaining answers. Please refrain from adding this to your questions.

– halfer
Nov 20 '18 at 17:55





Please read Under what circumstances may I add “urgent” or other similar phrases to my question, in order to obtain faster answers? - the summary is that this is not an ideal way to address volunteers, and is probably counterproductive to obtaining answers. Please refrain from adding this to your questions.

– halfer
Nov 20 '18 at 17:55












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53397723%2funderstanding-conditional-jumps%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53397723%2funderstanding-conditional-jumps%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Guess what letter conforming each word

Port of Spain

Run scheduled task as local user group (not BUILTIN)