What will be in CH and AH after these commands?
MOV AX, 1234
MOV BP, AX
MOV DX, 999
MOV DI, DX
MOV CH, 222 [bp+di]
Short answer: AH will contain the high byte of AX (so, 12h if AX was loaded with 1234h). CH will contain a single byte read from memory — not the multi‑byte value 1DEFh itself. In the hex example the effective 16‑bit offset comes out to 1DEFh, so the CPU fetches the byte at SS:1DEFh and places that byte (00h–FFh) into CH.
How the address is formed: the offset is the sum of the base/index registers plus the displacement. With the hex values used by the OP the math is
0x1234 + 0x0999 + 0x0222 = 0x1DEF. That 1DEFh is an address (16‑bit offset); the byte at that address is what ends up in CH. If the sum wraps past 0xFFFF it just wraps modulo 0x10000 — the offset is always 16 bits.
A few important clarifications (addressing gaps in the thread):
BP participates in the effective address, the default segment is SS, not DS. So the load comes from SS:1DEFh unless a segment override is used. This corrects the mistaken DS: reference earlier.AH/CH are 8‑bit registers. They can only hold 0x00–0xFF. A computed 16‑bit address like 1DEFh cannot be placed into CH directly by a memory load — only a byte stored at that address can.h (and prefix a leading 0 if the hex starts with A–F). NASM accepts 0x form. Be explicit to avoid the decimal/hex confusion seen above.Practical tip from : verify with a debugger or emulator (DOSBox/debug or any 16‑bit emulator) and initialize the target memory to a known pattern so the load is deterministic.
Jump to Post— thines01 401Do you have DEBUG?
You can run this through DEBUG just like in your last post.
Jump to Post— wildgoose 420Build trace tables!
MOV AX, 1234 AX:1234 CH:-- DI:---- DX:---- BP:---- MOV BP, AX AX:1234 CH:-- DI:---- DX:---- BP:1234 MOV DX, 999 AX:1234 CH:-- DI:---- DX:999 BP:1234 MOV DI, DX AX:1234 CH:-- DI:999 DX:999 BP:1234 MOV CH, 222 [bp+di] ? <-- [2455] <-- [1234 + 999 + …
Do you have DEBUG?
You can run this through DEBUG just like in your last post.
Build trace tables!
MOV AX, 1234 AX:1234 CH:-- DI:---- DX:---- BP:----
MOV BP, AX AX:1234 CH:-- DI:---- DX:---- BP:1234
MOV DX, 999 AX:1234 CH:-- DI:---- DX:999 BP:1234
MOV DI, DX AX:1234 CH:-- DI:999 DX:999 BP:1234
MOV CH, 222 [bp+di] ? <-- [2455] <-- [1234 + 999 + 222] Okay, so ah will have 12(because ax has 1234)
but in the last line the values are given hexadecimal, so 222+1234+999 is 1DEF, not 2455. ch will have 1def.
Is this correct?
You used decimal not HEX so no!
You used a decimal 1234 which is hex 04d2, so AH=04, AL=D2.
If you meant hex, you should have had 1234h 999h 222h etc.
And no to your second question!
MOV CH, 222 [bp+di] ? <-- [2455] <-- [1234 + 999 + 222]
[ ] <-- memory reference by. The 222 appears outside the braces but in reality are part of the memory reference!
But the teacher told us that when you write 222 is hex by default.
Okay, let's say it's:
MOV AX, 1234h
MOV BP, AX
MOV DX, 999h
MOV DI, DX
MOV CH, 222h [bp+di]
Now, does ah has 12, and does ch has 1DEF?
If your instructor has been programming for years then you heard them wrong. in Assembly language it's in decimal unless it has a (h) (H) as a suffice. If the first ASCII character in the hex is A,B,C,D,E,F then it needs to be preceeded with a 0 so as not to be confused with a label!
1234h is okay
0FACEh is okay
FACEh is NOT okay! It's a label!
We have no idea what is in ch because it is loaded from a byte in memory at location
ds:[0997]
and we have no idea what is in memory at that location as there is no provided block of memory to observe!
BUT, ch can not have 1DEF as ch is an 8-bit register therefore 00h - FFh
OMG you totally cleared this up for me. Thx a lot!! You really helped me :)
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.