Does it fit in a byte?

A byte holds 0 to 255. When an addition gives a larger result, the byte keeps only the low 8 bits and the carry flag CF becomes 1.

What to build

Read a digit d, and find out if d × 50 fits in a byte, by adding 50 to a byte register d times.

Requirements

  • Add 50 to AL, d times, starting from 0.
  • If any of the additions sets the carry flag, print wraps. If no addition does, print fits.
  • Do not use MUL.

Input

One digit d, then Enter.

Output

fits or wraps, on one line.

Constraints

0 ≤ d ≤ 9.

Example

Input:

3

Output:

fits

Why it works

The total goes 50, 100, 150, 200, 250 and then 300, which is too big. The sixth addition leaves AL = 44 and sets CF = 1. So the program prints fits for d up to 5, and wraps from d = 6. Testing the flag right after each ADD is important, because the next instruction that changes the flags would hide it.

Examples

Example 1 · Input
3
Expected output
fits
Example 2 · Input
6
Expected output
wraps

Hints

Hint 1

Keep the running total in AL, starting at 0, and add 50 to it `d` times with ADD AL, 50 and a LOOP.

Hint 2

After each ADD, JC (jump if carry) tells you that the total no longer fits in a byte. Jump to the message for a carry.

Hint 3

Guard the loop with JCXZ in case d is 0.

Solution

Show one correct solution (try it yourself first)
; Does it fit in a byte?
.MODEL SMALL
.STACK 100H
.DATA
    FITS  DB 'fits$'
    WRAPS DB 'wraps$'
.CODE
MAIN PROC
    MOV AX, @DATA
    MOV DS, AX
    MOV AH, 1
    INT 21H
    SUB AL, '0'
    MOV CL, AL
    MOV CH, 0           ; CX = d
    MOV AL, 0           ; the total
    JCXZ OK
ADDING:
    ADD AL, 50
    JC WRAP             ; CF = 1: it did not fit
    LOOP ADDING
OK:
    LEA DX, FITS
    JMP SHOW
WRAP:
    LEA DX, WRAPS
SHOW:
    MOV AH, 9
    INT 21H
    MOV AH, 4CH
    INT 21H
MAIN ENDP
END MAIN

▶ Open this solution in the compiler, then press Visualize to watch it run step by step

Lesson: Arithmetic and the flags →