flat assembler
Message board for the users of flat assembler.
Index
> DOS > What is wrong with this code? |
Author |
|
Matrix 19 Nov 2004, 13:26
Kristian_ wrote: Hi! that is because al is lower 8 bits of ax, and ax is lower 16 bits of eax, so, if you put 1 in ax, then ah will be zeroed out btw.: ax has ah - high part and al - low part you can use the registers for whatever except segment registers, and sp if you modify them , you should then restore, or don't use stack for example if you're using ss,sp you got this wrong there Code: mov ah, 9 ; for text output mov ax, 4 ah is high part of ax to see what you're doing: Code: mov ah,$09 ; for text output mov ax,$0004 ; high 2 nibbles, then low 2 nibbles |
|||
19 Nov 2004, 13:26 |
|
crc 19 Nov 2004, 13:34
Code: org 256 mov ax, 4 mov bx, 4 cmp ax, bx je true ; if(ax == bx){ goto true; } else { jmp false ; goto false; } true: mov dx, msg ; You forgot the 'mov' mov ah, 9 ; Setting ax above cleared this, so we move it here int 21h int 20h false: int 20h msg DB "TRUE$" 1) Setting ax will clear ah and al, so set ah later in the function. 2) No need to do push ax followed immediately by pop ax 3) This could be done more cleanly... |
|||
19 Nov 2004, 13:34 |
|
crc 19 Nov 2004, 13:36
A cleaner version:
Code: org 256 mov ax, 4 mov bx, 4 cmp ax, bx jne false ; skip the following if ax <> bx ; True: do this mov dx, msg mov ah, 9 int 21h false: ; True condition will reach this and exit int 20h msg DB "TRUE$" |
|||
19 Nov 2004, 13:36 |
|
Kristian_ 19 Nov 2004, 17:55
Thank you!
Quote: ax has ah - high part and al - low part What does it mean? For example AX register is 16bit: [ AH 8bit]+[ ?? 8bit] = AX AX has like two registers in it right? For example if I store this value into AX register 'ab', then AH will contain 'a' and other will contain b? |
|||
19 Nov 2004, 17:55 |
|
bubach 19 Nov 2004, 18:20
[ AH 8bit]+[ AL 8bit] = AX ...
example: Code: mov ah, 0x03 mov al, 0x7E ; AX is now: 0x037E |
|||
19 Nov 2004, 18:20 |
|
Kristian_ 19 Nov 2004, 19:00
Thank you!
So if AH = 1 and AL = 2 then AX = 12 NOT 3 right? And is this the same for BX, CX and DX? |
|||
19 Nov 2004, 19:00 |
|
Matrix 19 Nov 2004, 21:13
0 1 = BIT Boolean Algebra is 0 or 1
AL = 8 bits = byte AL = 10101010 ; 8 bits AH = 01010101 ; 8 bits AX = 16 Bits = word now AX is AH then AL AH = 01010101 ; 8 bits + AL = 10101010 ; 8 bits = AX = 01010101+10101010 = 0101010110101010 and if AX = 0101010110101010 then EAX low 16 bits are AX so eax is now EAX = 16 times 0 then 16 BITS AX=0101010110101010 EAX = 0000000000000000 0101010110101010 all registers are the same EAX EBX ECX EDX ESI (32 bit register) 's low 16 bits are accessible via SI 32 bit one > 16 bit part EDI > DI ESP > SP EBP > BP before you ask they do not have a byte part seperately segments are 16 bits only ds es fs gs ss |
|||
19 Nov 2004, 21:13 |
|
Kristian_ 19 Nov 2004, 21:26
Thank you! But for what are segments used for?
|
|||
19 Nov 2004, 21:26 |
|
vid 20 Nov 2004, 17:10
http://www.decard.net/?body=tajga&chapter=chap03
it's chapter 3.3. Not very detailed but may give you a pricture. |
|||
20 Nov 2004, 17:10 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.